|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
以一万行测试,第一、二种都要30秒上下,第三种则不到0.1秒。
- Sub 去重1()
- timA = Timer
- Sheets("名称").Select
- R = [a65536].End(xlUp).Row
- N = 0
- For i = 2 To R Step 1
- If WorksheetFunction.CountIf(Columns(1), Cells(i - N, 1)) > 1 Then
- Rows(i - N).Delete
- N = N + 1
- End If
- Next
- MsgBox (Timer - timA)
- End Sub
复制代码
- Sub 去重2()
- timA = Timer
- Sheets("名称").Select
- R = [a65536].End(xlUp).Row
- For i = R To 2 Step -1
- If WorksheetFunction.CountIf(Columns(1), Cells(i, 1)) > 1 Then
- Rows(i).Delete
- End If
- Next
- MsgBox (Timer - timA)
- End Sub
复制代码
- Sub 去重3()
- Dim i%, N%, R%, S() As String, V
- timA = Timer
- Sheets("名称").Select
- R = [a65536].End(xlUp).Row
- Range("A2:A" & R).Sort KEY1:=[A2], Order1:=1, Header:=xlNo
- V = Range("A2:A" & R + 1).Value
- ReDim S(1 To R)
- For i = 1 To R - 1 Step 1
- If V(i, 1) <> V(i + 1, 1) Then
- N = N + 1
- S(N) = V(i, 1)
- End If
- Next
- Range("A2:A" & R).ClearContents
- Range("A2").Resize(R, 1) = Application.Transpose(S)
- MsgBox ("共用时" & Timer - timA)
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|