ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sumproduct operation in VBA array (https://www.excelbanter.com/excel-programming/315257-sumproduct-operation-vba-array.html)

Dave Gallagher

Sumproduct operation in VBA array
 
Greetings and TIA for your time
I have a worksheet crosstab to sumarise a worksheet database by using
Sumproduct formulas. As an exercise, I would like to confine the calculations
to memory and finish by transfering the pre-calculated array to a range on
the worksheet...

Im trying the following approach:
From the database, load fields "Title" and "Country" into TitleArray and
CountryArray (into memory)
From the Crosstab row and column headers, load TitleHeaderArray and
CountryHeaderArray into memory.

Next, calculate each cell of the CrosstabArray in memory:
For i = 1 to Range("CountryHeader").cells.count
For j = 1 to Range("TitleHeader").cells.count
CrosstabArray(i , j) = _
Worksheetfunction.sumproduct(Arg1, Arg2)
next
next

I'm strugling with Arg1 & 2. If Arg1 were on the worksheet it would be:
--(Title = $A3) where A3 is the intersection of the current row and the range
"TitleHeader". Similarly, on the worksheet version, Arg2 would be: --(Country
= B$2)

For the VBA version i've tried for Arg1: (TitleArray = TitleHeaderArray(i))
and similar for Arg2: (CountryArray = CountryHeaderArray(j))

Am I completly off track? please help



All times are GMT +1. The time now is 05:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com