Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loop got stuck (Excel vba)

Status
Not open for further replies.

houde

Programmer
Jan 24, 2005
13
US
Hello!
I tried to automate a stupid work that I am doing in Excel right now: Copying names down into the cells below that are empty. The problem is that the loop doesn't really work, it only jumps between cells C2 and C3 - anybody knows what I did wrong? Your help would be very much appreciated!! Cheers, Fabian

Sub fab99()
'
' fab99 Macro
' Macro recorded 2005/02/01 by Fabian WYSS
'

'
Dim i As Integer
Dim k As Integer
i = 2
k = 3
Do
Cells(i, k).Select
If Cells(i, k).Value = "" Then
Cells(i, k).Value = Cells(i - 1, k).Value
Cells(i + 1, k).Select
Else: Cells(i + 1, k).Select
End If
Loop Until i = 400

End Sub
 
You have to increment i somewhere in the loop, or use a For .. Next construction:
k = 3
For i = 2 To 400
If Cells(i, k).Value = "" Then Cells(i, k).Value = Cells(i - 1, k).Value
Next i

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
you need to increment i. There are better ways of looping but to solve this one, just add:

i=i+1

between

End If

and

Loop Until i = 400


Rgds, Geoff

"Three things are certain: Death, taxes and lost data. Guess which has occurred"

Please read FAQ222-2244 before you ask a question
 
Hey guys,
Thank you very much! I am learning so much from you! I hope one day I will know enough so I don't have to bother you any more!!! Thanks thanks thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top