max array formula in vba

prlondhe

Board Regular
Joined
Jan 4, 2014
Messages
54
Hi

I have a sheet where column a contains a code, another sheets column p contains the age of the member. There can be 6 members under the code

Now i want to have a array formula in vba to find the max value in column p for code equal to code in sheet a.


sheet a
col a col b
111
112
and so on

sheet 2
col a col b col c
111 1 58
111 2 56
112 1 60
112 2 55
112 3 25
112 4 23
and so on

Can anybody help
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi,

Much as I like VBA i think a Worksheet Formula will be easiest:

Excel 2013
AB
1ColAColB
211158
311260
41130
Sheet1
Cell Formulas
RangeFormula
B2{=MAX(IF(Sheet2!$A$2:$A$7=A2,Sheet2!$C$2:$C$7))}
B3{=MAX(IF(Sheet2!$A$2:$A$7=A3,Sheet2!$C$2:$C$7))}
B4{=MAX(IF(Sheet2!$A$2:$A$7=A4,Sheet2!$C$2:$C$7))}
Press CTRL+SHIFT+ENTER to enter array formulas.



Excel 2013
ABC
1ColAColBColC
2111158
3111256
4112160
5112255
6112325
7112423
Sheet2
 
Upvote 0
hI

Thank your for your reply. But I only want the max value for that particular code to perform more calculations. using a small VBA code to further calculate on the basis of max value. can u pls help on vba code
 
Upvote 0
It is difficult to provide a complete solution without knowing the complete problem.

The code below will look at the list in Sheet2 and find the maximum value for each column A value. That data is then held in a Dictionary where it can be looked up either by index number or by key. I have included an example of both.

Code:
Sub VBAMax()
    Dim arr  As Variant
    Dim dic  As Object
    Dim i    As Long
    Dim key  As String

    With ThisWorkbook.Worksheets("Sheet2")
        arr = .Range("A2", .Cells(.Rows.Count, "A").End(xlUp)).Resize(, 3)
    End With
    
    Set dic = CreateObject("Scripting.dictionary")
    For i = 1 To UBound(arr)
        key = arr(i, 1)
        If dic(key) < arr(i, 3) Then dic(key) = arr(i, 3)
    Next
    
    key = 112
    MsgBox "Key: " & key & " has max " & dic(key)
    
    For i = 0 To dic.Count - 1
        Debug.Print dic.keys()(i); dic.items()(i)
    Next
End Sub

Regards,
 
Last edited:
Upvote 0

Forum statistics

Threads
1,222,951
Messages
6,169,217
Members
452,239
Latest member
fadhlatef

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