Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8655709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:06:09+00:00 2026-06-12T15:06:09+00:00

I am getting this run-time error 9 , Subscript Out of range in Excel

  • 0

I am getting this run-time error 9 , Subscript Out of range in Excel VBA 2003 while creating charts,

Somewhere in the code, Public Chrt_color As Variant and also
'Assigning the chart colors
Chrt_color = Array(4, 7, 9, 10, 11, 12, 13, 14, 17, 18, 21, 22, 23, 3, 43, 51, 50, 39, 47, 52, 56)

Public Sub label_creation_Chart5(ByRef wksht As Excel.Worksheet)


Dim i As Integer
Dim j As Integer
Dim iTemp As Integer
Dim cht_Num As Integer
Dim iTextBoxLoc As Integer
Dim dbTemp As Double
Dim vSeriesValues As Variant
Dim dbSeriesLastValue() As Double


Application.ScreenUpdating = False
cht_Num = 5

wksht.ChartObjects("Chart 5").Activate
wksht.ChartObjects("Chart 5").Select

Do While ActiveChart.TextBoxes.Count > 0
    ActiveChart.TextBoxes(1).Delete
Loop

If ActiveChart.SeriesCollection.Count < 1 Then GoTo Sub_end

ReDim dbSeriesLastValue(1 To ActiveChart.SeriesCollection.Count) As Double
ReDim iSeriesIndex(1 To ActiveChart.SeriesCollection.Count) As Integer

For i = 1 To ActiveChart.SeriesCollection.Count
    vSeriesValues = ActiveChart.SeriesCollection(i).Values

    If wksht.Range("AJ" & (i + 52)).Value = "Yes" Or _
       (prdName = "" And InStr(wksht.Range("A" & (i + 52)).Value, corpName) > 2) Then
        ActiveChart.SeriesCollection(i).Border.ColorIndex = 5
        wksht.Range("Z" & (i + 52) & ":AH" & (i + 52)).Font.ColorIndex = 5
    Else
        ActiveChart.SeriesCollection(i).Border.ColorIndex = Chrt_color(i)
        wksht.Range("Z" & (i + 52) & ":AH" & (i + 52)).Font.ColorIndex = Chrt_color(i)
    End If

    dbSeriesLastValue(i) = vSeriesValues(UBound(vSeriesValues, 1))
    iSeriesIndex(i) = i
    iTextBoxLoc = 12 + 202 * (1 - (vSeriesValues(UBound(vSeriesValues, 1)) / (ActiveChart.Axes(xlValue).MaximumScale - ActiveChart.Axes(xlValue).MinimumScale)))
    With ActiveChart.TextBoxes.Add(195, iTextBoxLoc, 100, 13)
        .AutoSize = True
        .Text = ActiveChart.SeriesCollection(i).Name
        With .Font
            .Name = "Arial"
            .Size = 7
            .ColorIndex = ActiveChart.SeriesCollection(i).Border.ColorIndex
        End With
    End With
Next i
For i = 1 To (ActiveChart.SeriesCollection.Count - 1)
    For j = i + 1 To ActiveChart.SeriesCollection.Count
        If dbSeriesLastValue(j) < dbSeriesLastValue(i) Then
            dbTemp = dbSeriesLastValue(j)
            dbSeriesLastValue(j) = dbSeriesLastValue(i)
            dbSeriesLastValue(i) = dbTemp
            iTemp = iSeriesIndex(j)
            iSeriesIndex(j) = iSeriesIndex(i)
            iSeriesIndex(i) = iTemp
        End If
    Next j
Next i

I am getting the error at ActiveChart.SeriesCollection(i).Border.ColorIndex = Chrt_color(i)
Also value of ActiveChart.SeriesCollection(i).Border.ColorIndex = -4105 is showing in intermediate window when the error occurs.

Please help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:06:11+00:00Added an answer on June 12, 2026 at 3:06 pm

    I’d look at the value of i when you get the error message. Your code iterates i from to the number of series. Say you had more series than the elements of Chtr_color, then Chrt_color(i) doesn’t evaluate beyond.

    Another problem might be the series index goes from 1 to N while the array index goes from 0 to N-1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this script, I keep getting an error: Run-time error '1004': Method 'Range'
I am getting this run time error when using IID_IWebBrowser2 interface of CLSID_InternetExplorer. Run-Time
I am Getting a run time Exception while using this code Runtime rt =
I am getting this following error during run time. ERROR: thread attach failed My
I'm getting this run-time error and I'm really struggling to get to the bottom
I'm trying this SQL statement but I keep getting an error Run-time error '3061':
I'm getting this error when I try run DB:Rake : ** Invoke db:migrate (first_time)
I am getting this error when I run db:migrate Mysql2::Error: Table 'sample_app_development.microposts' doesn't exist:
I keep getting this error when I run my web app (asp.net mvc) in
I am getting this error when I run the following code: #!/usr/bin/env ruby -rubygems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.