looping trouble

  • Thread starter Thread starter Hru48
  • Start date Start date
H

Hru48

Hey all,

I'm trying to get this formula to loop around putting the result in
column E until column D is empty but i've tied my brain in a knot, can
someone point out where i'm going wrong,

thanks!!

Sub FUGGLE()
Dim K As Long

Sheets("EL").Select
Range("D8").Select


Do Until ActiveCell.Value = ""
'Do Until ActiveCell.Offset(0, -1).Value = ""

ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "=(RC[-1]/R3C[-1])*100"

ActiveCell.Offset(1, 0).Select

K = K + 1

Loop
 
You need to move back before you move down:


starting at D8 you move across to E8 and deposit the formula.
you then move down to E9 (NOT BACK TO D8). However, E9 is empty, so the
loop stops
 
Sub FUGGLE()
Dim K As Long

Sheets("EL").Select
Range("D8").Select


Do Until ActiveCell.Value = ""
'Do Until ActiveCell.Offset(0, -1).Value = ""

ActiveCell.Offset(0, 1).Select
ActiveCell.FormulaR1C1 = "=(RC[-1]/R3C[-1])*100"

'move back to D first!!
ActiveCell.Offset(0, -1).Select
ActiveCell.Offset(1, 0).Select

K = K + 1

Loop
End Sub
 
Ok got it thanks!

One more thing though, I have three blocks of these to do - is there
anyway I can write them all into one sub?

say this one start on d8 and the next one would be g8 next i8?
 
I would set it up with three separate loops, not knowing if there are as many
items in the other columns as in D.


I also have to admit that it is easier to replicate the code than to re-work
it into a more general form. (a good programmer would create a sub and call
it three times)
 
Back
Top