insert sum when first blank cell found

A

amorrison2006

I have data in a worksheet.

I have two rows between each of my lines of data.

What I need is a macro to insert a sum calculation for everything
above until the last sum calculation. The numbers are contained in
column A

I hope this makes sense.

Thanks

Andrea
 
G

Guest

You have something like this

1 5
2 6
3 =sum(a1:a2)
4
5 7
6 8
7 =sum(A3:a6)
8
9 35
10 36
11 =sum(a7:a10)

if you copy =sum(a3:a6) and past it in all the first blank rows it will
automatically increment to meet your requirements.
 
A

amorrison2006

I wanted a macro to do this automatically.....


Rather than me do it manually.....


Thanks

Andrea
 
G

Guest

Try this

Sub copysum()

EndRow = Cells(Rows.Count, "A").End(xlUp).Row

FirstRow = 1
RowCount = 1
Do While RowCount <= EndRow + 1

If IsEmpty(Cells(RowCount, "A")) Then

LastRow = RowCount - 1
Cells(RowCount, "A").FormulaR1C1 = _
"=SUM(R" & CStr(FirstRow) & "C1:R" & _
CStr(LastRow) & "C1)"

FirstRow = RowCount
RowCount = RowCount + 1

End If

RowCount = RowCount + 1
Loop

End Sub
 

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