![]() |
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 |
All times are GMT +1. The time now is 05:59 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com