Associate the maximum value with another value in the same row but a different column

iand5

New Member
Joined
Jul 26, 2017
Messages
36
I currently have the code below to find the maximum value in a column. After finding the maximum value I need to associate that number with another value in the same row but a different column. I want to find the maximum value in the range ("AX6:AX29"). I need to associate that number with a value in column A.

It's currently giving me the wrong value.
Code:
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; white-space: inherit;">[COLOR=#303336][FONT=inherit]Dim r As Long
    Dim t As Long
    Dim rslt As String
    With Worksheets("RESOURCE") ' Change to your sheet
        r = Application.WorksheetFunction.Max(.Range("AX6:AX29"))
        t = Application.Match(r, .Range("A6:A29"))
        rslt = .Cells(t, "A")
        Debug.Print rslt
    End With

[/FONT][/COLOR][COLOR=#101094][FONT=inherit]End[/FONT][/COLOR][COLOR=#303336][FONT=inherit] [/FONT][/COLOR][COLOR=#101094][FONT=inherit]With
[/FONT][/COLOR]</code>
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
You didn't allow for the offset of starting at row 6:
Although this would just return the same value as r
Code:
Sub test()
Dim r As Long
    Dim t As Long
    Dim rslt As String
    With Worksheets("RESOURCE") ' Change to your sheet
        r = Application.WorksheetFunction.Max(.Range("AX6:AX29"))
        t = Application.Match(r, .Range("A6:A29"))
        rslt = .Cells(t + 5, "A")
        Debug.Print rslt
    End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,304
Members
452,633
Latest member
DougMo

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