Subscript out of Range every time?


New Member
Aug 12, 2019
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


MrExcel MVP
May 26, 2009
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:


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

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...