Replicating INDIRECT within VBA

duffry

New Member
Joined
Mar 6, 2013
Messages
5
So I have a funky lookup formula that I use all over a sheet.


Code:
=SUMPRODUCT(SUMIFS(nameRange1,    nameRange2, A$1,    nameRange3,  INDIRECT($B$1)))

This let me build a report page with many of these style lookups, changing nameRange1 depending on the column of data I want in that cell.
nameRange2 is a date column in the data source, and cell B1 holds a reference to the name of the group of data I want (shoes, books etc).
I then could duplicate the worksheet and change the content of cell B1 and all my many formulas would find the stuff they need.
The references are on a separate settings sheet. Sometimes they refer to a single cell and other times to a whole table of data ("Table1[#Data]").

This all works just fine.

I'm now trying to replicate some of this function within VBA to save a JSON output of some of the data.
I want to continue to be able to administer the groupings of items (shoes in Table1, books in Table2 etc) in the same way but am struggling to reproduce the above formula in VBA.

I have gotten as far as:
Code:
    numThings = numThings & _
        Application.WorksheetFunction.SumProduct( _
            Application.WorksheetFunction.SumIfs( _
                Names("nameRange1").RefersToRange, _
                Names("nameRange2").RefersToRange, Names("reportDate").RefersToRange.Value + Names("intervalTimes").RefersToRange(1).Value, _
                Names("nameRange3").RefersToRange, Application.WorksheetFunction.indirect("Table1[#Data]") _
            ) _
        )

But it doesn't like it at all.
I have tested all other elements on their own and they work, it's just the indirect that fails (also doesn't swap in capital letters in the same way as SumIfs etc, so assuming it's not supported).

I played about with something like
Code:
Worksheets("Settings").ListObjects("Table1").DataBodyRange
But with similar results.

Is there any clue anyone can offer me to help?
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try...

Code:
Dim MyCritRng As Variant
Dim MyResult As Double

Set MyCritRng = Evaluate("INDIRECT($B$1)")

MyResult = Evaluate("=SUMPRODUCT(SUMIFS(nameRange1,nameRange2,A$1,nameRange3," & MyCritRng.Address & "))")

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,215,603
Messages
6,125,782
Members
449,259
Latest member
rehanahmadawan

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