excel vba 去除重复字段的代码
时间: 2024-05-14 17:15:29 浏览: 107
以下是一个使用 VBA 去除重复字段的代码:
```
Sub RemoveDuplicates()
Dim lRow As Long
Dim lCol As Long
Dim i As Long
Dim j As Long
Dim dict As Object
Set dict = CreateObject("Scripting.Dictionary")
With ActiveSheet
lRow = .Cells(.Rows.Count, "A").End(xlUp).Row
lCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
For i = lRow To 2 Step -1
dict.RemoveAll
For j = 1 To lCol
If dict.Exists(.Cells(i, j).Value) Then
.Rows(i).Delete
Exit For
Else
dict.Add .Cells(i, j).Value, 0
End If
Next j
Next i
End With
End Sub
```
这段代码假设重复字段在表格中是完全相同的。如果你希望仅去除特定列的重复字段,可以在代码中修改 `j` 的范围。
阅读全文