Have VBA/macro repeat process in Excel

Joined
Mar 25, 2009
Messages
13
Reaction score
0
I started the vba process below as a macro, but now would like to add to it code to step down two rows and repeat the process (loop) at that point, maybe until it reaches a null value (or the first blank row in the spreadsheet.

What I am trying to do is have it insert a new row after every two rows of data, and sum the two rows of data (in a single column).

Rows("4:4").Select
Selection.Insert Shift:=xlDown
Range("A2:A4").Select
Range("A4").Activate
ActiveCell.FormulaR1C1 = "=SUM(R[-2]C:R[-1]C)"
Range("A2:A4").Select
 
Last edited:
Joined
Mar 25, 2009
Messages
13
Reaction score
0
Found it elsewhere (below) that worked:

Sub Macro1()

r = 4 'assumes header
mc = 1 'column A
lr = Cells(Rows.Count, mc).End(xlUp).Row
Do Until Cells(r - 1, mc) = ""
Rows(r).Insert
Cells(r, mc) = "sum is " & _
Application.Sum(Cells(r - 2, mc).Resize(2))
r = r + 3
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