1
我有一个excel表,重复几千行。 3种类的列可能会重复,例如在下面显示的第二行中
有没有办法使excel循环遍历一行并删除行内的重复项,以便它最终看起来像显示的第二个表下面?
我有一个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
正是我在找的东西......而且比我打算接近它要优雅得多。谢谢! – dah97765
您的意思是'H&SS GA0141 7/1/2006'是在第二栏还是第三栏?示例数据的屏幕截图肯定有助于:) –
r1c1:GS r1c2:GA0202 r1c3:7/1/2006 r2c1:H&SS r2c2:GA0141 r2c3:7/1/2006 r2c4:H&SS r2c5:GA0141 r2c6:7/1/2006 r2c7:H&SS r2c8:GA0141 r2c9:7/1/2006 – dah97765
noob问题:SE允许我们上传屏幕截图吗?还是我们只需链接到某个第三方主机? – dah97765