How do You Set a Value to Equal The Greater Of Two Values? VBA Excel

killpaddy

Board Regular
Joined
Jul 31, 2012
Messages
52
Hello,

I have the following code inside a For loop:

Code:
        ARow1 = Range("A" & i).row
        ARow2 = Range("A" & "1:A" & z).Find(Trim(Range("C" & i).Value)).row
        CRow1 = Range("C" & i).row
        CRow2 = Range("C" & "1:C" & z).Find(Trim(Range("A" & i).Value)).row
        
        ARow = ?
        CRow = ?

I want 'ARow' to equal the greater of 'ARow1' and 'ARow2' (and the same for 'CRow') without having to use an If statement; it seems like the kind of thing that would have a VBA function already, but I dont know what it is. Can anyone help?

Also what would be the equivalent for the lesser of two values

Thanks
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
This seems to work:

Code:
Sub maxVal()
Dim rw As Long, rw1 As Long, rw2 As Long
rw1 = Rows(6).Row
rw2 = Rows(7).Row
rw = WorksheetFunction.Max(rw1, rw2)
MsgBox rw
End Sub
Code:
 
Upvote 0

Forum statistics

Threads
1,215,497
Messages
6,125,158
Members
449,208
Latest member
emmac

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