一个朋友找我看看能不能用程序把Excel里的重复行删除下,呵呵,看VBA代码吧。
Option Explicit Sub delSameRows() '删除某一列中相同的行 '此例为 先手动按B列排序,然后用此代码找到B列中相同的值再删除整行 Dim i As Long, j As Long Dim startRows As Long, endRows As Long '起止行数 startRows = 2 endRows = 38006 For i = startRows To endRows For j = i + 1 To endRows If Range("B" & j).Value = Range("B" & i).Value Then 'Set Rng = Cells(j, 2) 'Rng.Interior.ColorIndex = 6 Rows(j).Delete j = j - 1 endRows = endRows - 1 Else Exit For End If Next Next MsgBox "已完成!剩余行数 " & endRows End Sub |
受教了!呵呵!