I have the below code that iterates correctly. My issue is setting the module variables so that I know where this code ended and to set the variables so when I run another Sub it will use the module variables at the top as the starting point. I am not sure if these are getting set and read properly.
The first code is the one that runs initially and is SUPPOSE to set the ending cell as the sub ends The second sub is suppose to read in the module variable and set a start point from that location. I have not used global type variables in Excel and I think that is my issue.
Thank you
The first code is the one that runs initially and is SUPPOSE to set the ending cell as the sub ends The second sub is suppose to read in the module variable and set a start point from that location. I have not used global type variables in Excel and I think that is my issue.
Thank you
VBA Code:
Dim lastStartCell As Range
Dim lastEndCell As Range
Sub ColorCells()
Dim numIterations As Integer
numIterations = InputBox("How many iterations do you want to perform?")
Dim startCell As Range
Set startCell = Range("B2")
Dim i As Integer
For i = 1 To numIterations
startCell.Offset((i - 1) * 1, (i - 1) * 1).Resize(4).Interior.Color = RGB(255, 0, 0)
Next i
'set variables for start and end cells of the last bar
Set lastStartCell = startCell
Set lastEndCell = startCell.Offset(4, 0)
End Sub
Sub NextColorRowsx()
Dim numIterations As Integer
numIterations = InputBox("How many iterations do you want to perform?")
Dim startCell As Range
Set startCell = lastStartCell
Dim i As Integer
For i = 1 To numIterations
startCell.Offset((i - 1) * 1, (i - 1) * 1).Resize(4).Interior.Color = RGB(255, 0, 0)
Next i
'set variables for start and end cells of the last bar
' Set lastStartCell = startCell.Offset(0, 0)
' Set lastEndCell = startCell.Offset(4, 0)
End Sub