English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I will be summing sets of numbers with different #'s of rows. I want to be able to run a macro below a set of numbers and have it do =sum(that range of numbers)
I've tried doing the 'record macro' but it writes the code, for example) as:
ActiveCell.FormulaR1C1 = "=SUM(R[-4]C:R[-1]C)"

the next set of numbers might have 20 numbers, or 2, but it won't always be 4.

2007-03-15 14:40:50 · 1 answers · asked by jimbobbighouse 4 in Computers & Internet Software

1 answers

You can do this by saving a flag about the last row intereded in the sum from the previous summation
Let me assume you set a cell (Like R2) as that flag, so the first summation will take that cell value (Zero) as the initial flag, like this

ActiveCell.FormulaR1C1 = "=SUM(R" & Val(Range( "R2").value) +1 & "C:R[-1]C)"
Range( "R2").Value = ActiveCell.Row

So, the next sum, R2 will have the number of the last cell with sum + 1 to be used in

Trust me, it is me who can do it

Oh, yea, I am the VBAXLMan

2007-03-17 23:57:20 · answer #1 · answered by Anonymous · 0 0

fedest.com, questions and answers