View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Don Guillett[_2_] Don Guillett[_2_] is offline
external usenet poster
 
Posts: 1,522
Default deleting repeated rows

try this

Sub keepsmallestvalue()
lr = Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 2 Step -1

Set mf = Cells(1, 1).Resize(lr - 1) _
.Find(What:=Cells(i, 1), after:=Cells(1, 1), _
LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

If Not mf Is Nothing Then
If Cells(i, 2) < Cells(mf.Row, 2) _
Then Rows(mf.Row).Delete
End If

Next i
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"dummy" wrote in message
...
I have a sheet with a list of items in column A and a quantity in Column B.
In the case where I have identical items in column A, I only want to see
the
row with the lesser column B quantity and delete the others.
Example: Starting with
A B
BK152 500
CV136 600
BK152 400

I would like to end up with
A B
BK152 400
CV136 600


Thus throwing out the row with the original quantity of 500 for item BK152

Thanks for any help