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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,432
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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:

zaser

New Member
Joined
Aug 12, 2019
Messages
7
Okay so I made the change and it doesn't cause an error, but it doesn't change the cell values?
 

Watch MrExcel Video

Forum statistics

Threads
1,130,042
Messages
5,639,722
Members
417,107
Latest member
derekMG

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
Top