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

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Be easier to use subtotal function:

VBA Code:
returnVal(0) = Application.WorksheetFunction.Subtotal(4, .Range("A1:A" & krow))
 
Upvote 0
Thanks. Would that allow me to use .Address at the of it?
i can get the max of the column with no issue. The problem the name of associated to it in column B
for example if the max value in column A is in A3. I want to get the address and offset it by 1 using .Address.Offset(0,1) to shift to B3 and get the value in B3.
 
Upvote 0
Just replace your worksheetfunction.max in the code with the subtotal and it should do what you ask. You cant use slanted “ they need to be straight " so you need to replace them in the Set rg line.
 
Upvote 0
Thanks for your reply. Although it’s works for the returnVal(0). It does not for rg. It’s still coming up empty.
 
Upvote 0
@steve the fish,

Why do you think there are hidden rows? Unless I missed it, I don't see that mentioned anywhere.

Hi Rick. From the code in the opening post I presumed he was using a filter:

VBA Code:
 returnVal(0) = Application.WorksheerFunction.Max (.Range(“A1:A” & krow).SpecialCells(xlTypeVisible))
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

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