删除Excel中重复的行的小脚本
删除某项与前面重复的行的VBA脚本
目标:如果某行的X列的值跟某行的X列的值相等,则视此行为重复的行,予以删除.
脚本如下:
Sub deleteDouble()
'用户输入
Dim userInput
userInput = Application.InputBox("输入需要检查的起始行,结束行,以及需要检察的列,格式如 1,20,C")
Dim arrUserInput
arrUserInput = Split(userInput, ",")
Dim theColumn
theColumn = Asc(arrUserInput(2)) - 64 '进行检验的列
Dim theStart
theStart = arrUserInput(0) '起始行
Dim theEnd
theEnd = arrUserInput(1) '最后一行的号码.
Dim i '每一行的号码
Dim j '
For i = theStart To theEnd
For j = i + 1 To theEnd '从当前行至结尾.
If Cells(i, theColumn) = Cells(j, theColumn) Then
Rows(j).Delete
End If
Next
Next
End Sub