通过如下的VBA代码,可以实现EXCEL指定列的重复值
t = ThisWorkbook.Path & "\1.txt"
Set d = CreateObject("scripting.dictionary")
'cells(1,1),cells(4,4)
Dim StartRow As Integer
StartRow = InputBox("请输入查重的起始行 ", "请输入查重的起始行")
Dim StartColumn As Integer
StartColumn = InputBox("请输入查重的起始列 ", "请输入查重的起始列")
Arr = Range(Cells(StartRow, StartColumn), Cells(StartRow, StartColumn)).CurrentRegion
For i = 1 To UBound(Arr)
If Not d.exists(Arr(i, 1)) Then
d(Arr(i, 1)) = ""
Else
p = p & "," & Arr(i, 1)
End If
Next
Open t For Output As #1
x = Split(p, ",")
For i = 1 To UBound(x)
Print #1, x(i)
Next
Close #1
代码使用方法:
在EXCEL文件的当前目录,新建一个1.txt的文本文件。通过上述代码,会检查指定的列,将其重复的值,存放到1.txt里面。