LoginSignup
2
1

More than 3 years have passed since last update.

RemoveDuplicatesで動的配列を使用する

Last updated at Posted at 2020-10-07

特定の列を指定するのではなく、全列で重複を削除するケース
単にColumns:=arrで失敗したので対処方法を調査。
CvarでVariantをVariantに変換。。。
うまくいったみたいです。

'選択範囲の全列で重複を削除
Sub Selection_RemoveDuplicates()

    With Selection

        Dim i As Long
        Dim arr As Variant

        ReDim arr(.Columns.Count - 1)
        For i = 0 To UBound(arr)
            arr(i) = i + 1
        Next
        'ヘッダーはYesにしているがケースバイケースならGuessでも。
        .RemoveDuplicates Columns:=CVar(arr), Header:=xlYes

    End With

End Sub
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1