Do Until Loop

R

ryguy7272

I'm still not good with setting up loops. I'm trying to create a simple
macro to sum the values in columns L through O, and put the results in Column
P. i want the loop to run until it detects blanks in Column K.

Sub FillDown()
Range("P2").Select
Do Until ActiveCell.Offset(-5, 1) = ""
ActiveCell.FormulaR1C1 = "=SUM(RC[-4]:RC[-1])"
ActiveCell.Offset(1, 0).Select
Loop
End Sub


Please help!
Thanks,
Ryan--
 
F

FSt1

hi
try this....
Sub FillDown()
Dim r As Range
Dim rd As Range
Dim ro As Range

Set r = Range("K2")
Do While Not IsEmpty(r)
Set rd = r.Offset(1, 0)
Set ro = r.Offset(0, 5)
ro.FormulaR1C1 = "=SUM(RC[-4]:RC[-1])"
Set r = rd
Loop
End Sub

varibles work much better than activecell. it also speeds up the macro
because you not selecting anything.

Regards
FSt1
 
R

ryguy7272

Awesome, simply awesome!
Thanks!

--
RyGuy


FSt1 said:
hi
try this....
Sub FillDown()
Dim r As Range
Dim rd As Range
Dim ro As Range

Set r = Range("K2")
Do While Not IsEmpty(r)
Set rd = r.Offset(1, 0)
Set ro = r.Offset(0, 5)
ro.FormulaR1C1 = "=SUM(RC[-4]:RC[-1])"
Set r = rd
Loop
End Sub

varibles work much better than activecell. it also speeds up the macro
because you not selecting anything.

Regards
FSt1

ryguy7272 said:
I'm still not good with setting up loops. I'm trying to create a simple
macro to sum the values in columns L through O, and put the results in Column
P. i want the loop to run until it detects blanks in Column K.

Sub FillDown()
Range("P2").Select
Do Until ActiveCell.Offset(-5, 1) = ""
ActiveCell.FormulaR1C1 = "=SUM(RC[-4]:RC[-1])"
ActiveCell.Offset(1, 0).Select
Loop
End Sub


Please help!
Thanks,
Ryan--
 

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