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?
 

Some videos you may like

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,299
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!
 

Watch MrExcel Video

Forum statistics

Threads
1,108,954
Messages
5,525,876
Members
409,668
Latest member
mitunsLax

This Week's Hot Topics

Top