Delete rows based on max value

Ron512

Board Regular
Joined
Nov 17, 2002
Messages
98
I would appreciate assistance with a macro that would delete all rows with the same value in Column A that have a value less than the max value in column B.

Thanks

Ron

Sample Data

AB
Florida200
Florida210
Florida150
Georgia130
Georgia151
]

Desired result

AB
Florida210
Georgia151
]
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
This assumes a layout (with headers) as shown below:
Book1
AB
1StateValue
2Florida200
3Florida210
4Florida150
5Georgia130
6Georgia151
Sheet1 (5)

VBA Code:
Sub Ron512()
Dim R As Range
Set R = Range("A1:B" & Cells(Rows.Count, "A").End(xlUp).Row)
With R
    .Sort key1:=[B2], order1:=xlDescending, Header:=xlYes
    .RemoveDuplicates Columns:=1, Header:=xlYes
End With
    
End Sub
 
Upvote 0
Joe, Thanks for the quick reply. It works perfectly based on the criteria I provided. After a look at the complete data set and putting more thought into the required results the task is more complicated. I will put together a better description of the criteria and sample data. Do you suggest I continue in this thread or mark it solved and start a new one?
 
Upvote 0
Joe, Thanks for the quick reply. It works perfectly based on the criteria I provided. After a look at the complete data set and putting more thought into the required results the task is more complicated. I will put together a better description of the criteria and sample data. Do you suggest I continue in this thread or mark it solved and start a new one?
You are welcome.

You can continue this thread if the thread title remains reasonably descriptive.

Whatever you do, please use XL2BB to post the sample data .... makes it much easier to copy the data for testing w/o typing.
XL2BB - Excel Range to BBCode
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,796
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top