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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
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,216,099
Messages
6,128,818
Members
449,469
Latest member
Kingwi11y

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