Column Max Location

stuhba

New Member
Joined
Jul 21, 2014
Messages
10
I have a large data set with multiple sheets each with 40k+ values. I have written a macro loop to get the maximum for each column and need to get the row where that value occurs. Macro is as follows:

For n = 1 To numyears
Cells(4 + n, 1).Value = n
Cells(4 + n, 3).Value = Worksheets(SheetPtr).Cells(2, n + 2)
Cells(4 + n, 4).Value = WorksheetFunction.Max(Worksheets(SheetPtr).Columns(n + 2))
Next n
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Haven't been able to get syntax right to select that range on the worksheet. It doesn't seem to like the fact that I am using a counter in the sheet name.
 
Last edited:
Upvote 0
try: Application.WorksheetFunction.Match(WorksheetFunction.Max(Worksheets(SheetPtr).Columns(n + 2)), Range("A:A"), 0)

I wasn't sure what range you were looking at, so used Column A, but you can put in any variable you want.

If you put a variable = the above string, then the variable will equal the row number the max value appears in.
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,799
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