Excel VBA – 删除行内的重复

朋友们,

我有一个excel表,重复了几千行。 3列的类别,可能会重复,如下面显示的第二行

有没有一种方法可以使excel在一行中循环,并删除行中的重复项,使其最终看起来像下面显示的第二个表格?

在这里输入图像说明

我不确定这是你正在尝试的吗?

 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