Find the offset value of the max of a column

Jimmy509

New Member
Joined
Apr 18, 2019
Messages
29
Hey guys
I am working on this code and my plan is to go into a worksheet, get the max of column A. And if the max is found then go to the next row over and get the name associated with it. I wrote this code and the value of the name is coming up blank and I don’t what I am doing wrong.

Dim returnVal (2), rg, rg2 as variant
Dim krow as long
Dim Ws1 As worksheet
krow = ws1.Cells(Rows.Count,1).End(xlUp).Row
With Ws1
returnVal(0) = Application.WorksheerFunction.Max (.Range(“A1:A” & krow).SpecialCells(xlTypeVisible))
Set rg = .Range(“A1:A” & krow).Find(returnVal(0), , xlValues, xlWhole, , False, False, False)
If Not rg is Nothing Then
rg2 = rg.Offset(0,1).Value
returnVal(1) = rg2
Set rg = Nothing
End if
End with
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
@steve the fish,

You should be using 104 as the first argument for your Subtotal function (not 4).


@Jimmy509,

Here is a function that returns the name next to the first maximum value it finds in the specified range... you can pull the single line of code out of the function and embed it in your own code if you wish)...
VBA Code:
Function GetMaxName(Rng As Range) As String
  GetMaxName = [VLOOKUP(SUBTOTAL(104,A:A),A:B,2,0)]
End Function
 
Upvote 0
Hmm, you are right... both 4 and 104 work. So a row hidden by a filter is not a hidden row according to SUBTOTAL then... it is considered something else instead. Interesting.

So, it appears that the 104 can be replaced by 4 in the code I posted in Message #13 if desired.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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