I'm trying to use an array to store offset values that refer to cells whose contents I want to change only while my macro is running, and then at the end of the macro I want to revert to the value I had when the macro started.
The cells can only contain "include" or "exclude", which control what series appear in a chart. However for the purposes of the macro I need all of those cells to say "include". To do so I setup this code to change them and populate the array:
This executes without issue (at least to the extent that no errors are thrown by Excel). Later Once I've done what I needed I try to use the array to revert the cells I changed thusly (I never change l's value after the first loop, so that if I, for example, change 3 of the 6 cells I check, l is still 3 when I start this loop):
When I hit the first line inside the loop (Range("C3"). ...) Excel says the subscript is out of range. I've tried poking around on this an a couple other sites for some guidance, but I'm not seeing anything that seems to help.
Thanks in advance!
The cells can only contain "include" or "exclude", which control what series appear in a chart. However for the purposes of the macro I need all of those cells to say "include". To do so I setup this code to change them and populate the array:
Code:
k= 0
Do While k < 6
'Check row 3 of the column k columns to the left of C
If Range("C3").Offset(0, k).Value = "Exclude" Then
'Set the cell back to Include
Range("C3").Offset(0, k).Value = "Include"
'Resize ResetCells to length l
ReDim ResetCells(l) As Long
ResetCells(l) = k
l = l + 1
End If
k = k + 1
Loop
This executes without issue (at least to the extent that no errors are thrown by Excel). Later Once I've done what I needed I try to use the array to revert the cells I changed thusly (I never change l's value after the first loop, so that if I, for example, change 3 of the 6 cells I check, l is still 3 when I start this loop):
Code:
Do While l - 1 > 0
'go to the cell indicated by ResetCells(l)
Range("C3").Offset(0, ResetCells(l)).Value = "Exclude"
l = l - 1
Loop
When I hit the first line inside the loop (Range("C3"). ...) Excel says the subscript is out of range. I've tried poking around on this an a couple other sites for some guidance, but I'm not seeing anything that seems to help.
Thanks in advance!