Dear All,
I am fairly new to VBA and I am having trouble getting the below code to run correctly.
I am trying to create a counter that will increment from 0 up to the maximum number set in the cell named “selected”. So if the cell “selected” contains the number 10, the cell “counter” will increase from 0 to 1 to 2, etc until it reaches the maximum of 10 and ideally would then loop back to 1 again.
When I run the code in ‘step into’ mode, it works fine, but when I run the entire code, it jumps straight ahead to 9 and I cannot figure out why.
Any help would be really appreciated!
Thank you for your time.
Best regards,
Shirley
sub counterincrement()
Dim a As Integer
Dim b As Integer
Dim c As Integer
' "selected" is the cell showing number of visible rows in a filtered list (eg 10). The counter below should not exceed this number
' "counter" is the name of the cell which should increment from 0 up to maximum number in selected cell
a = Range("selected").Value
b = Range("counter").Value
c = 0
Do
Range("counter").Value = c
c = c + 1
Loop Until c = a
End Sub
I am fairly new to VBA and I am having trouble getting the below code to run correctly.
I am trying to create a counter that will increment from 0 up to the maximum number set in the cell named “selected”. So if the cell “selected” contains the number 10, the cell “counter” will increase from 0 to 1 to 2, etc until it reaches the maximum of 10 and ideally would then loop back to 1 again.
When I run the code in ‘step into’ mode, it works fine, but when I run the entire code, it jumps straight ahead to 9 and I cannot figure out why.
Any help would be really appreciated!
Thank you for your time.
Best regards,
Shirley
sub counterincrement()
Dim a As Integer
Dim b As Integer
Dim c As Integer
' "selected" is the cell showing number of visible rows in a filtered list (eg 10). The counter below should not exceed this number
' "counter" is the name of the cell which should increment from 0 up to maximum number in selected cell
a = Range("selected").Value
b = Range("counter").Value
c = 0
Do
Range("counter").Value = c
c = c + 1
Loop Until c = a
End Sub