EXCEL删除被重复了的所有数据的函数
2008-09-28 13:05
459 查看
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 = 1
'以下不需要修改
Dim EndRow As Integer: EndRow = Sheets(sheetsCaption).Range(Col & "65536").End(xlUp).Row
Dim Count_1 As Integer: Count_1 = 0
Dim j As Integer: j = 0
Dim i As Integer: i = StartRow
With Sheets(sheetsCaption)
Do
j = i + 1
Count_1 = 0
Do
If .Range(Col & i) = .Range(Col & j) Then
Count_1 = 1
.Range(Col & j).EntireRow.Delete
j = j - 1
EndRow = Sheets(sheetsCaption).Range(Col & "65536").End(xlUp).Row
End If
j = j + 1
Loop While j < EndRow + 1
If Count_1 = 1 Then
.Range(Col & i).EntireRow.Delete
EndRow = Sheets(sheetsCaption).Range(Col & "65536").End(xlUp).Row
i = i - 1
End If
i = i + 1
Loop While i < EndRow
End With
MsgBox "删除成功!"
Application.ScreenUpdating = True
End 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 = 1
'以下不需要修改
Dim EndRow As Integer: EndRow = Sheets(sheetsCaption).Range(Col & "65536").End(xlUp).Row
Dim Count_1 As Integer: Count_1 = 0
Dim j As Integer: j = 0
Dim i As Integer: i = StartRow
With Sheets(sheetsCaption)
Do
j = i + 1
Count_1 = 0
Do
If .Range(Col & i) = .Range(Col & j) Then
Count_1 = 1
.Range(Col & j).EntireRow.Delete
j = j - 1
EndRow = Sheets(sheetsCaption).Range(Col & "65536").End(xlUp).Row
End If
j = j + 1
Loop While j < EndRow + 1
If Count_1 = 1 Then
.Range(Col & i).EntireRow.Delete
EndRow = Sheets(sheetsCaption).Range(Col & "65536").End(xlUp).Row
i = i - 1
End If
i = i + 1
Loop While i < EndRow
End With
MsgBox "删除成功!"
Application.ScreenUpdating = True
End Sub
相关文章推荐
- Excel查找筛选并删除重复数据
- Oracle 删除重复数据之分析函数
- Oracle 分页查询 查询一个表中从某行到某行的数据; 删除 删除一张表中所有重复的行(只留重复行中的一行); 删除一张表中指定重复的行(只留重复行中的一行);
- Excel中删除两列中重复的数据[原创]
- 高手支招:三步批量删除excel 2007的重复数据
- EXCEL删除重复数据的多种方法
- 在oracle数据库表中删除所有重复的数据,仅保留一条记录
- sql中删除重复行(所有列的数据都是相同的只保留一条数据)
- Excel删除重复数据
- excel删除重复数据
- 利用Access实现Excel中多表合并,并删除重复数据的问题
- sqlserver中多行所有数据重复,无法更新或删除问题
- SQL删除所有重复数据。
- Excel中删除重复的数据
- SQL 已更新或删除的行值要么不能使该行成为唯一行(sqlserver中有多行所有的列重复的数据,无法更新或删除问题)
- Excel中删除重复数据(用VBA代码)
- sqlserver中多行所有数据重复,无法更新或删除问题,通常是在没有主键的情况下的表
- Excel 中删除重复的数据
- Excel中删除重复数据
- 使用ORACLE开窗函数over()进行重复数据的删除【自用】