Mega Code Archive

 
Categories / VisualBasic Script / Language Basics
 

Use GoTo to do a loop

Sub BadLoop()     Dim StartVal As Long     Dim NumToFill As Long     Dim CellCount As Long     StartVal = InputBox("Enter the starting value: ")     NumToFill = InputBox("How many cells? ")     ActiveCell = StartVal     CellCount = 1 DoAnother:     ActiveCell.Offset(CellCount, 0) = StartVal + CellCount     CellCount = CellCount + 1     If CellCount < NumToFill Then GoTo DoAnother _        Else Exit Sub End Sub