Cell reference

jarhead58

Active Member
Joined
Sep 21, 2017
Messages
364
Office Version
  1. 2021
Platform
  1. Windows
Good morning!
How can I get the cell address of a cell value that is found using worksheetfunction.Max? TIA
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
It depends on how you're using .Max. Here's one way:

VBA Code:
Sub test2()

    x = WorksheetFunction.Max(Range("M:M"))
    MsgBox Range("M:M").Find(x).Address
    
End Sub
 
Upvote 0
Or possibly like below, with formula?

Book1
AB
1
2MMax Address
31$A$7
42
599
63
7263
85
96
10nd
1188
x
Cell Formulas
RangeFormula
B3B3=CELL("address",INDEX(A1:A12,SUMPRODUCT((A1:A12=MAX(A1:A12))*(ROW(A1:A12))),1))
 
Upvote 0
Or possibly like below, with formula?

Book1
AB
1
2MMax Address
31$A$7
42
599
63
7263
85
96
10nd
1188
x
Cell Formulas
RangeFormula
B3B3=CELL("address",INDEX(A1:A12,SUMPRODUCT((A1:A12=MAX(A1:A12))*(ROW(A1:A12))),1))

Thanks for the reply but Eric W put me in the right direction!!
 
Upvote 0
It depends on how you're using .Max. Here's one way:

VBA Code:
Sub test2()

    x = WorksheetFunction.Max(Range("M:M"))
    MsgBox Range("M:M").Find(x).Address
   
End Sub

It depends on how you're using .Max. Here's one way:

VBA Code:
Sub test2()

    x = WorksheetFunction.Max(Range("M:M"))
    MsgBox Range("M:M").Find(x).Address
   
End Sub

That works great! Now when I try to Set firstloc = Range("Y32:Y57").Find(first).Address,
I get a type mismatch error from .Address. I'm just trying to get the value from the cell 2 columns to the left of the "first" address. What am I missing?


VBA Code:
Dim rng As Range, cell As Range
    Dim first As String
    Dim firstlocval As Range
    Dim firstloc As Range
    Dim second As String
    Dim third As String
    Dim fourth As String
    Dim fifth As String
    
    Set rng = Range("Y32:Y57")
    first = WorksheetFunction.Max(Range("Y32:Y57"))
    Set firstloc = Range("Y32:Y57").Find(first).Address
    Set firstlocval = firstloc.Offset(0, -2)
    MsgBox (firstlocval)
 
Upvote 0
If you want to point firstloc at the cell, take the Address method off:

VBA Code:
Set firstloc = Range("Y32:Y57").Find(first)
 
Upvote 0
If you want to point firstloc at the cell, take the Address method off:

VBA Code:
Set firstloc = Range("Y32:Y57").Find(first)

Hmm...it returns "15", which is in col W row 39 while my "first" is in col Y row 50. I should be getting "3" which is 2 cells to the left of "first" or W 50
 
Upvote 0
What value is in Y39?
What Value is in Y50?
What does the code below produce?

VBA Code:
Sub cTest()
    Dim first As String
    first = WorksheetFunction.Max(Range("Y32:Y57"))
    MsgBox first
End Sub

I suspect that you will need to specify certain parameters in the Find.
 
Upvote 0
What value is in Y39?
What Value is in Y50?
What does the code below produce?

VBA Code:
Sub cTest()
    Dim first As String
    first = WorksheetFunction.Max(Range("Y32:Y57"))
    MsgBox first
End Sub

I suspect that you will need to specify certain parameters in the Find.

The code produces "9" which is in Y50. W50, what I am trying to find, is "3". Instead, it gives me the value of W39.
 
Upvote 0
There were 3 questions, you have answered 2.

and what does the code below produce?
VBA Code:
Sub dTest()
Dim first As Long
Dim firstlocval As Range
Dim firstloc As Range 
first = WorksheetFunction.Max(Range("Y32:Y57"))
Set firstloc = Range("Y32:Y57").Find(first)
Set firstlocval = firstloc.Offset(0, -2)
MsgBox (firstlocval)
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,642
Messages
6,125,987
Members
449,276
Latest member
surendra75

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