Reputation: 61
VBA code
Sub colourcode()
Dim tcol As Integer, ro As Integer, co As Integer
ro = 2
co = 2
tcol = 10
For i = 1 To tcol
Cells(ro, co).Interior.Color = RGB(0, 0, 0)
ro = ro + 2
Next
'I want to reset a variable ro value to its default value which is 2.
End Sub
Upvotes: 0
Views: 1060
Reputation: 166331
If you want to minimize your maintenance issues use a constant for the starting point:
Sub colourcode()
Const RO_START As Long = 2
'any other fixed value...
Dim tcol As Long, ro As Long, co As Long
ro = RO_START
co = 2
tcol = 10
For i = 1 To tcol
ActiveSheet.Cells(ro, co).Interior.Color = RGB(0, 0, 0)
ro = ro + 2
Next
ro = RO_START 'reset, avoiding repeating the 2
End Sub
Upvotes: 1