View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
kkknie[_93_] kkknie[_93_] is offline
external usenet poster
 
Posts: 1
Default Group and Delete

This will do it:

Code
-------------------
Sub test()

Dim i As Long
Dim lastVal As String
Dim lastRow As Long

lastRow = Range("A65536").End(xlUp).Row
lastVal = ""

For i = Range("A65536").End(xlUp).Row To 1 Step -1
If Range("A" & i).Value & Range("B" & i).Value = lastVal Then
Range("A" & i).EntireRow.Delete
End If
lastVal = Range("A" & i).Value & Range("B" & i).Value
Next

End Su
-------------------

It assumes that the group you speak of is column a and b. It works b
starting at the bottom and working up. If the values in columns a an
b are the same as the last ones, it will delete them. Since it goe
bottom to top, it keeps the bottom most ones.

After reading your message, you cang change the places where I us
Range("A" & i).Value & Range("B" & i).Value to just Range("A"
i).Value since you only specified Customer ID.

New code would be
Code
-------------------
Sub test()

Dim i As Long
Dim lastVal As String
Dim lastRow As Long

lastRow = Range("A65536").End(xlUp).Row
lastVal = ""

For i = Range("A65536").End(xlUp).Row To 1 Step -1
If Range("A" & i).Value = lastVal Then
Range("A" & i).EntireRow.Delete
End If
lastVal = Range("A" & i).Value
Next

End Su
-------------------





--
Message posted from http://www.ExcelForum.com