Excel查找重复值

由于项目需求,经常需要处理客户的一些数据,往往会有些重复的

这时我们就要想办法把重复的去掉,以前总是用数据库,现在想直接

用Excel就把它处理好,找到了解决办法

1、用函数(03、07)

2、删除重复(07)

3、VBA(03、07)

我这里就讲最常用的,第一种,使用if函数嵌套countif函数处理,用一个标志,if(countif(A1:A17,A1)>1,"same",“”)

然后就用自动筛选,筛选所有标识为same的

然后就把这些重复的删掉就ok,

以上是03的做法,

07的做法很简单

然后点击ok即可

第3种VBA

保留不重复的记录行,重复的只保留一行。
1、打开有重复数据的EXCEL
2、Alt+F11 打开宏的VB编辑器
3、左边双击:ThisWorkBook
4、贴入以下代码并运行即可:
Sub 删除重复数据()
'删除col列的重复数据
'本例是删除标题为sheet1的EXCEL表中A列(从A2单元格开始)的重复数据
Application.ScreenUpdating = False
'可根据实际情况修改下面三行的结尾值
Dim sheetsCaption As String: sheetsCaption = "Sheet1"
Dim Col As String: Col = "A"
Dim StartRow As Integer: StartRow = 2
'以下不需要修改
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
5、按F5键运行即可

猜你喜欢

转载自blog.csdn.net/ITBread/article/details/6058480
今日推荐