So I have a funky lookup formula that I use all over a sheet.
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:
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
But with similar results.
Is there any clue anyone can offer me to help?
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
Is there any clue anyone can offer me to help?