Subscript out of Range every time?

zaser

New Member
Joined
Aug 12, 2019
Messages
7
I keep getting a "subscript out of range" error on the If statement. I've tried changing the start index to 0 and 1 and it still had this error.

Sorry the codes messy, part of the reason I've been messing around with a lot of different ways to declare the array.

I'm trying to alter values of a chart Series without messing up the data I have down. I'm trying to do this by setting the series arrays of the data ranges and then changing the elements. Problem is I can't figure out how to iterate through the arrays and change the values, it says I'm out of bounds?




Dim ColumnData() As Variant, c As Chart, s As Series, g As Integer
ReDim ColumnData(EndNumber - StartNumber)
g = 1
Set c = ActiveChart


For i = 20 To 29
Set s = c.SeriesCollection(g)
ColumnData = Range(Cells(StartNumber, i), Cells(EndNumber, i))
s.Values = ColumnData
For j = LBound(ColumnData, 1) To UBound(ColumnData, 1) - 1
If ColumnData(j) = 5 Then
ColumnData(j) = 4
End If
Next j
g = g + 1
Next i
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Untested, but try deleting the ReDim line and changing ColumnData(j) to ColumnData(j,1) wherever it appears.

EDIT: Also, change Dim ColumnData() as Variant to Dim ColumnData as Variant.
 
Last edited:
Upvote 0
Okay so I made the change and it doesn't cause an error, but it doesn't change the cell values?
 
Upvote 0

Forum statistics

Threads
1,214,534
Messages
6,120,086
Members
448,944
Latest member
sharmarick

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top