I'm learning VBA and I tried nesting a do-while-loop inside a for-loop, but the outer for-loop doesn't seem to have an effect (whole Sub only runs once), although its runs without errors. Could someone please assist me? :)
My code:
Sub DoWhileDemo()
Dim Cnt As Integer
Cells(1, 1).Activate 'just meant as an in-case
For Cnt = 1 To 100 Step 1
Do While ActiveCell.Value <> Empty
ActiveCell.Value = ActiveCell.Value * 2
ActiveCell.Offset(1, 0).Select
Loop
Next Cnt
End Sub
ActiveCellis not empty? And should it beActiveCell.Offset(1, 0).Activate? If not, it just keep checking and working onA1ActiveCell(which is not a recommended way to do this), you set the cell in the next row. If that cell is empty, it will never trigger yourDo Whileloop and hence nothing will ever get done. Move yourActiveCell.Offset(1, 0).Selectoutside yourDo Whileloop. That might help