Find the highest value in column A and delete the whole row

VBAProIWish

Well-known Member
Joined
Jul 6, 2009
Messages
1,027
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I need code that will find the highest value in column A and delete that whole row..

Thanks!
 
Try this:
Code:
Option Explicit

Sub DeleteMaxRow()
'Jerry Beaucaire   6/3/2010
'Find highest value in column A and delete that row

Dim delRw   As Long
Dim delVal  As Double

    delVal = Application.WorksheetFunction.Max(Range("A:A"))
    delRw = Application.WorksheetFunction.Match(delVal, Range("A:A"), 0)
    
    Rows(delRw).Delete xlShiftUp

End Sub
 
Upvote 0
What if there are two or more rows with the largest value?
 
Upvote 0
If you need to delete ALL the rows that have the highest value, in case of duplicates, use this instead.
Code:
Option Explicit

Sub DeleteMaxRow()
'Jerry Beaucaire   6/3/2010
'Find highest value in column A and delete that row

Dim delRw   As Long
Dim delVal  As Double

    delVal = Application.WorksheetFunction.Max(Range("A:A"))
    delRw = Application.WorksheetFunction.Match(delVal, Range("A:A"), 0)
    
On Error Resume Next
    Do
        Rows(delRw).Delete xlShiftUp
        delRw = 0
        delRw = Application.WorksheetFunction.Match(delVal, Range("A:A"), 0)
    Loop Until delRw = 0

End Sub
 
Upvote 0
Domenic, JB...

Once I got my answer, I didn't see the responses after my reply. This macro was basically needed to delete the auto-sum row, so there would never be a duplicate highest value, but good forward thinking and resolving on both of your parts nonetheless!

Thanks again
 
Upvote 0

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