Converting AGGREGATE formula to VBA code

Samuelkmh

New Member
Joined
Jul 2, 2019
Messages
4
I have this formula that works but I can seem to convert it to a VBA code. When I run the code, there is no error, but no value appears. Appreciate your help.

My formula:
INDEX('[Balanced Portfolio AA_280219.xlsx]Summary Table'!D78:CR298,AGGREGATE(14,6,(ROW('[Balanced Portfolio AA_280219.xlsx]Summary Table'!D78:D298)-ROW('[Balanced Portfolio AA_280219.xlsx]Summary Table'!D78)+1)/(('[Balanced Portfolio AA_280219.xlsx]Summary Table'!B78:B298 =D3)*(INDEX('[Balanced Portfolio AA_280219.xlsx]Summary Table'!D78:CR298,0,MATCH(B2,'[Balanced Portfolio AA_280219.xlsx]Summary Table'!D5:CR5,0))<>"")),1),MATCH(B2,'[Balanced Portfolio AA_280219.xlsx]Summary Table'!D5:CR5,0))


My code:
Set r2 = Application.WorksheetFunction.Index(sh1.Range("D78:CR298"), Application.WorksheetFunction.Aggregate(14, 6, ((sh1.Range("D78:D298").Row) - (sh1.Range("D78").Row) + 1) / ((sh1.Range("B78:B298") = comboSh1.Range("D3")) * (Application.WorksheetFunction.Index(sh1.Range("D78:CR298"), 0, Application.WorksheetFunction.Match(comboSh1.Range("B2"), sh1.Range("D5:CR5"), 0)) <> "")), 1), Application.WorksheetFunction.Match(comboSh1.Range("B2"), sh1.Range("D5:CR5"), 0))


I defined sh1 as '[Balanced Portfolio AA_280219.xlsx]Summary Table' from another workbook
and comboSh1 as the sheet in the active workbook.

I am trying to find obtain a value that has duplicated variables and hence I need this function.

I think there is something wrong when i tried to convert

AGGREGATE(14,6,(ROW('[Balanced Portfolio AA_280219.xlsx]Summary Table'!D78:D298)-ROW('[Balanced Portfolio AA_280219.xlsx]Summary Table'!D78)+1)/(('[Balanced Portfolio AA_280219.xlsx]Summary Table'!B78:B298 =D3)

into

Application.WorksheetFunction.Aggregate(14, 6, ((sh1.Range("D78:D298").Row) - (sh1.Range("D78").Row) + 1) / ((sh1.Range("B78:B298") = comboSh1.Range("D3"))

not sure how one range can be = to another range.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,223,888
Messages
6,175,203
Members
452,617
Latest member
Narendra Babu D

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