打印

[求助] 电子表格2003数据重复问题

0
如果只做这一次的话可以在表格中插入一列,在该列中输入=COUNTIF($A$1:$“表格最后一列列标”$“表格最后一行行标”,A1)
,最后将新插入的这一列进行降序排列,(从复的部分就在上面了)
如果要长期从事此工作,最好弄一个专用的宏
Sub 查找与删除重复数据2() '查找与删除col列的重复数据'
Application.ScreenUpdating = False  
'可根据实际情况修改下面三行的结尾值'
Dim sheetsCaption As String: sheetsCaption = "Sheet1"
Dim Col As String: Col = "C"  
Dim StartRow As Integer: StartRow = 4
'以下不需要修改'
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 WorksheetFunction.Trim(Format(.Range(Col & i), "<")) = WorksheetFunction.Trim(Format(.Range(Col & j), "<")) Then  
Count_1 = Count_1 - 1  
.Range(Col & i).EntireRow.Delete

.Range(Col & i).Select  

.Range(Col & i).Font.ColorIndex = 3

.Range(Col & j).Font.ColorIndex = 4  

ActiveCell.FormulaR1C1 = ActiveCell.FormulaR1C1 + "[#]"

MsgBox "第" & i & "与第" & j & "条数据重复"  
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  


这编辑模式写着真累
可能有空格或'的错误,用的时候需要排查下,也可以把注释删了在用
本帖最近评分记录
  • 那成 金币 +5 认真回复,奖励! 2013-12-5 23:49

TOP

当前时区 GMT+8, 现在时间是 2025-3-21 00:22