Note:
I already have a routine that will use a loop to determine Cumulative Sales.
My goal here is to use an Evaluate in cell formulas to obtain the
same results:
There are 12 ROWS related to Columns A B C
Column A is TIME with values 1 to 12
Column B is Sales with these Values
{10;25;100;250;600;1200;2000;3800;4900;2800;2100;800}
Column C is to be Cumulative Sales
which I cannot get to work
Below is code that fills up Columns A and B and FAILED code for Column C
The ONLY SOLUTION I am after is an Evaluate solution and this ASSUMES
that Evaluate can do this. I could be WRONG.
'---------------------
' Range
'---------------------
With WS_BD
.Range("A2") = "Time"
.Range("B2") = "Sales"
.Range("C2") = "*** Sales"
Set Rng_Time = .Range("A3:A14")
Set Rng_Sales = Rng_Time.Offset(0, 1)
Set Rng_***_Sales = Rng_Sales.Offset(0, 1)
End With
'---------------------
' Time - Column A
'---------------------
Rng_Time = Evaluate("Row(3:14)-2")
'---------------------
' Sales - Column B
'---------------------
' Uses Evaluate
' From Aaron Black post on OZGRID
' A comma represents Horizontal a semi-colon Vertical
'---------------------
'Note to reader: Dim MySales() as variant
MySales = [{10;25;100;250;600;1200;2000;3800;4900;2800;2100;800}]
Rng_Sales.Value = MySales
'---------------------
' Cumulative Sales - Column C
'---------------------
'Note - Actual Total Sales (for the 12 periods) are 18585
'The follow code starts out by just trying to get ANYTHING to work
'and then builds on that in an attempt to create a Cumulative formula
'This returns correct value
Rng_***_Sales.Formula = Evaluate("SUM(1+5)")
'This returns correct value
Rng_***_Sales.Formula = Evaluate("SUM(B2:B14)")
'Fills Cells with #NAME
Rng_***_Sales.Formula = Evaluate("SUM(RNG_SALES.ADDRESS)")
'This returns - all Cells have the value 18585
Rng_***_Sales.Formula = Evaluate("SUM(" & Rng_Sales.Address & ")")
'This returns - all Cells have the value 18585
Rng_***_Sales.Formula = Evaluate("SUM(" & Rng_***_Sales.Offset(0, -1).Address & ")")
'Trying to add IF ROW before the SUM
'Returns #VALUE
'From Bill Jelen's book page 127 based on a concept by PGCO1
Tmp = "If(ROW(3:14)"
Rng_***_Sales.Formula = Evaluate(Tmp & "," & "SUM(" & Rng_***_Sales.Offset(0, -1).Address & ")")
Thanks in advance if anyone goes after this.
John
Bookmarks