sum up an unknown number of rows

S

skoller

Hello. I think it's simple problem but as newbee in VBA it's a big one
for me.

First an example how my table could look like:
(I used simple numbers for the example, nomally these numbers are
calculated with several fomulars)

SET1
20
40
20
SUM: 80

SET2
20
30
SUM: 50

SET3
30
SUM: 30


The sum of every set should be calculated automatically with a
formular. Not a big deal but the problem is the following:
You can add new numbers in every Set with a makro. Therefore I don't
know how many rows I have to use to calculate the sum.
I need a script which sums all the rows between the beginning and the
end of every single set. The calculation of the sum should also work,
if you delete one row or number.

Thank you for any help in advance.

cheers
Stefan
 
B

Bob Phillips

n=0
For i = 1 to Cells(Rows.Count,"A").End(xlUp).Row
If Cells(i,"A").Value = "" Then
Cells(i,"A").Value = n
Else
If Left(Cells(i,"A").Value,3) <> "SET" Then
n = n + Cells(i,"A").Value
End If
End If
Next i

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top