Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default SUM with variable range

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

...



  #2   Report Post  
Posted to microsoft.public.excel.programming
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

...





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default SUM with variable range

I did try it, but couldn't really understand how it works. I tried
later again, and now I see how it works, and how it can be useful in
the future. But for this case, it messes up the table. The other
solution would be a better fit.

Thanks anyway, I learned another good function in Excel!

Jose


On Jun 13, 10:58 pm, "NickHK" wrote:
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


...- Hide quoted text -


- Show quoted text -



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
select range and put range address in variable [email protected] Excel Programming 2 January 25th 06 01:28 AM
Macro to copy a specified range to a variable range SWT Excel Programming 4 October 21st 05 08:24 PM
Range Variable ? Reuel Excel Programming 0 September 13th 05 10:30 PM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"