A step value can be included in a For-Next Loop. The step value determines how the counter is incremented. Change the active cell value to Counter to see the increment more clearly
Sub CountExample()
Dim Counter As Integer
For Counter = 1 To 100 Step 5
ActiveCell.Value = Counter
ActiveCell.Offset(1, 0).Select
Next Counter
End Sub
The macro might be more useful if the user can give their own counter and step values. We will introduce a couple of input boxes for this purpose:
Sub CountExample2()
Dim Counter As Integer
Dim ToNum As Integer
Dim StepNum As Integer
ToNum = InputBox("What maximum value do you want?")
StepNum = InputBox("What increment do you want?")
For Counter = 1 To ToNum Step StepNum
ActiveCell.Value = Counter
ActiveCell.Offset(1, 0).Select
Next Counter
End Sub |