EXCEL VBA 排序并删除某一列的重复数据
(2010-08-18 13:50:10)
标签:
移动宽带it |
分类: 移动、宽带__博客张凯_unikran |
Sub AX()
Call 排序
Call 删除重复数据
End Sub
Sub 排序()
End Sub
Sub 删除重复数据()
'以col列为条件删除的重复行数据
'本例是删除标题为sheet1的EXCEL表中以A列(从A2单元格开始)为条件的重复韩国数据
Application.ScreenUpdating = False
'可根据实际情况修改下面三行的结尾值
MsgBox "请确认子表名称是否是Sheet1?"
Dim sheetsCaption As String: sheetsCaption = "PSC"
MsgBox "请确认或修改到底 删除哪一列的重复数据?"
Dim Col As String: Col = "H"
MsgBox "请确认或修改该列的第几行开始核查所有数据是否有重复数据?"
Dim StartRow As Integer: StartRow = 1
'以下不需要修改
Dim EndRow As Integer: EndRow = Sheets(sheetsCaption).Range(Col
& "65536").End(xlUp).Row
Dim Count_1 As Integer: Count_1 = 0
Dim count_2 As Integer: count_2 = 0
Dim i As Integer: i = StartRow
With Sheets(sheetsCaption)
Do
Count_1 = Count_1 + 1
For j = StartRow To i - 1
If .Range(Col & i) = .Range(Col &
j) Then
Count_1 = Count_1 - 1
.Range(Col & i).EntireRow.Delete
EndRow = Sheets(sheetsCaption).Range(Col &
"65536").End(xlUp).Row
i = i - 1
count_2 = count_2 + 1
Exit For
End If
Next
i = i + 1
Loop While i < EndRow + 1
End With
MsgBox "共有" & Count_1 &
"条不重复的数据"
MsgBox "删除" & count_2 &
"条重复的数据"
Application.ScreenUpdating = True
End Sub