Selecting the Cell with the maximum value

hercat

New Member
Joined
Jan 22, 2008
Messages
8
Hello All, I'm writing a code where I want to select the cell with the maximum value.


I can get the address of that cell by using
=CELL("address",INDEX(C1:C360,MATCH(MAX(C1:C360),C1:C360,0)))

but this only works when I paste it into the spreadsheet directly. I want to use it in a VBA code, but when I try to use this to control the active cell, or even set it to be pasted into the spreadsheet to be used later, I get nothing but errors.

What I need is a line something like

ActiveCell.address = CELL("address",INDEX(C1:C360,MATCH(MAX(C1:C360),C1:C360,0)))

or anything that serves an equivalent function.

Any help you can offer is appreciated.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hello All, I'm writing a code where I want to select the cell with the maximum value.


I can get the address of that cell by using
=CELL("address",INDEX(C1:C360,MATCH(MAX(C1:C360),C1:C360,0)))


but this only works when I paste it into the spreadsheet directly. I want to use it in a VBA code, but when I try to use this to control the active cell, or even set it to be pasted into the spreadsheet to be used later, I get nothing but errors.

What I need is a line something like

ActiveCell.address = CELL("address",INDEX(C1:C360,MATCH(MAX(C1:C360),C1:C360,0)))

or anything that serves an equivalent function.

Any help you can offer is appreciated.
Try this:
Code:
Sub test()
Dim myAddress As String
myAddress = Application.Evaluate("CELL(""address"",INDEX(C1:C360,MATCH(MAX(C1:C360),C1:C360,0)))")
MsgBox myAddress
End Sub
 
Upvote 0
Hi Joe, this worked for the first part, but not for the selection of the relevant cell. I figured out how to make it work from your help above though, so thank you!

MaxVal = Application.Evaluate("CELL(""row"",INDEX(C1:C360,MATCH(MAX(C1:C360),C1:C360,0)))")
ActiveSheet.Cells(MaxVal, 1).Copy
 
Upvote 0

Forum statistics

Threads
1,207,108
Messages
6,076,590
Members
446,215
Latest member
userds5593

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