faint,blogger对编程语言的语法支持太滥了吧?还是我没有设置对?
============
一种方法,操作简单,步骤复杂的方法:
c2=exact(a2,b2)
把false筛选出来就ok。
另一种方法,使用vba。这个代码可以继续完善。
2009.02.06日发现这个vba代码的问题,不能备份,会把同一列所有相同的行都清除,只保留一个。已经修改了一下代码,首先复制选择的sheet,并新建一个相同的sheet。
http://www.hbjjrb.com/Jishu/Excel/200901/146677.html
请仔细阅读并修改相关数据。
1、打开有重复数据的EXCEL
2、Alt+F11 打开宏编辑器
3、左边双击:ThisWorkBook
4、贴入以下代码并运行即可:
‘删除同一个sheet里同一列里所有重复的数据
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
'复制需要修改的sheet,新建一个sheet
Sheets(sheetsCaption).Select
Sheets(sheetsCaption).Copy After:=Sheets(sheetsCaption)
'以下不需要修改
Dim EndRow As Integer: EndRow = Sheets(sheetsCaption).Range(Col & "65536").End(xlUp).Row
Dim Count1 As Integer: Count1 = 0
Dim count2 As Integer: count2 = 0
Dim i As Integer: i = StartRow
With Sheets(sheetsCaption)
Do
Count1 = Count1 + 1
For j = StartRow To i - 1
If .Range(Col & i) = .Range(Col & j) Then
Count1 = Count1 - 1
.Range(Col & i).EntireRow.Delete
EndRow = Sheets(sheetsCaption).Range(Col & "65536").End(xlUp).Row
i = i - 1
count2 = count2 + 1
Exit For
End If
Next
i = i + 1
Loop While i End With
MsgBox "共有" & Count1 & "条不重复的数据"
MsgBox "删除" & count2 & "条重复的数据"
Application.ScreenUpdating = True
End Sub
5、按F5键运行即可
======
修改了一下,只删除相邻行里重复的数据,不是全sheet查找除重,只是简单的去掉了那个循环,代码没有改动。
Sub 删除重复数据()
'删除col列的重复数据
'本例是删除标题为sheet1的EXCEL表中A列(从A2单元格开始)的重复数据
Application.ScreenUpdating = False
'可根据实际情况修改下面三行的结尾值
Dim sheetsCaption As String: sheetsCaption = "Sheet1"
Dim Col As String: Col = "C"
Dim StartRow As Integer: StartRow = 2
'复制需要修改的sheet,新建一个sheet
Sheets(sheetsCaption).Select
Sheets(sheetsCaption).Copy After:=Sheets(sheetsCaption)
'以下不需要修改
Dim EndRow As Integer: EndRow = Sheets(sheetsCaption).Range(Col & "65536").End(xlUp).Row
Dim Count1 As Integer: Count1 = 0
Dim count2 As Integer: count2 = 0
Dim i As Integer: i = StartRow
With Sheets(sheetsCaption)
Do
Count1 = Count1 + 1
'For j = StartRow To i - 1
j = i - 1
If .Range(Col & i) = .Range(Col & j) Then
Count1 = Count1 - 1
.Range(Col & i).EntireRow.Delete
EndRow = Sheets(sheetsCaption).Range(Col & "65536").End(xlUp).Row
i = i - 1
count2 = count2 + 1
'Exit For
End If
'Next
i = i + 1
Loop While i End With
MsgBox "共有" & Count1 & "条不重复的数据"
MsgBox "删除" & count2 & "条重复的数据"
Application.ScreenUpdating = True
End Sub