View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default SUM with variable range

Jose,
If you tried it you would see how it works.
But if you already have a solution, well go with that.

NickHK

"Jose" wrote in message
ups.com...
I am not familiar with the DataSubTotals menu, and don't know how it
works...

However, I came up with a solution that works. I basically create a
string with the formula I want to insert, like this:

(selection is column A)

a = 0
Str1 = "=SUM(R[-"
For Each b In selection.Cells
If Left(b.Value, 1) = " " Then
... here I copy the easy "=B1*C1" formula
Else
Str1 = Str1 + Trim(Str(a)) + "]C:R[-1]C)"
b.Offset(0, 3).FormulaR1C1 = Str1
a = -1
Str1 = "=SUM(R[-"
End If
a = a + 1
Next

Every time I put the sum formula for the cells above, I restart the
Str1 and a variables. It works beautifully!

Thanks anyway!
Jose


On Jun 13, 12:59 am, "NickHK" wrote:
That should be :
Maybe add a column for "Family", then look at DataSubTotals menu.

NickHK

"NickHK" wrote in message

...