View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
TFriis TFriis is offline
external usenet poster
 
Posts: 22
Default For To / Next loop doesn't update...

How come this sub only runs through i=1 and i=2, when k is obviously
updated during loop?

Sub Test()

k = 2
For i = 1 To k
Debug.Print k
If k = 2 Then k = 4
Next i

End Sub

I know this sub solves the problem, but I find Do While loops to be
clumsy - any other solutions?

Sub test2()

k = 2
i = 1
Do While i <= k
Debug.Print k
If k = 2 Then k = 4
i = i + 1
Loop


End Sub