1

友達、

数千行を繰り返す Excel テーブルがあります。以下に示す 2 行目のように、3 つの列のカテゴリが繰り返される場合があります。

行を Excel で循環させ、行内の重複を削除して、最終的に以下に示す 2 番目の表のようにする方法はありますか?

ここに画像の説明を入力

4

2 に答える 2

2

よくわかりませんが、これはあなたがしようとしていることですか?

Option Explicit

Sub Sample()
    Dim wsI As Worksheet
    Dim lastRow As Long, lastCol As Long, i As Long, j As Long
    Dim sVal1, sVal2, sVal3

    '~~> Input Sheet
    Set wsI = Sheets("Sheet1")

    With wsI
        lastRow = .Cells.Find(What:="*", After:=.Range("A1"), _
                  Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, _
                  SearchDirection:=xlPrevious, MatchCase:=False).Row

        lastCol = .Cells.Find(What:="*", After:=.Range("A1"), _
                  Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByColumns, _
                  SearchDirection:=xlPrevious, MatchCase:=False).Column

        For i = 1 To lastRow
            sVal1 = .Cells(i, 1).Value
            sVal2 = .Cells(i, 2).Value
            sVal3 = .Cells(i, 3).Value

            For j = 4 To lastCol Step 3
               If .Cells(i, j).Value = sVal1 And _
               .Cells(i, j + 1).Value = sVal2 And _
               .Cells(i, j + 2).Value = sVal3 Then
                    .Cells(i, j).ClearContents
                    .Cells(i, j + 1).ClearContents
                    .Cells(i, j + 2).ClearContents
               End If
            Next j
        Next i
    End With
End Sub
于 2012-05-10T16:32:15.323 に答える