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

  • SEARCH
  • Home
  • 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 8324941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:15:39+00:00 2026-06-09T00:15:39+00:00

I have what I hope is a relatively simple request. I am working on

  • 0

I have what I hope is a relatively simple request.

I am working on a macro which will automatically format a large number of charts that I am creating. I have got a problem, however, in that the number of series that each chart contains varies a lot.

If I try to run my current code on a chart that only has four series, for example, it errors when it reaches the code below and cannot process the code thereafter, as it is expecting a fifth series to format. I believe I need to implement code that says – “IF the chart has a fifth series THEN apply this next line of the macro”.

The code below is that which I am using to format each series. How should this be encased within an if statement as described above?

ActiveChart.LegEND.Select
ActiveChart.LegEND.LegendEntries(5).Select
ActiveChart.SeriesCollection(5).Select
With Selection.Format.Line
    .Visible = msoTrue
    .Weight = 1.5
End With
  • 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-09T00:15:41+00:00Added an answer on June 9, 2026 at 12:15 am

    You can use the Count member of the SeriesCollection collection (documentation), this returns the number of series in the chart. You could use something like:

    ActiveChart.LegEND.Select
    
    If ActiveChart.SeriesCollection.Count = 5 Then
    
        ActiveChart.LegEND.LegendEntries(5).Select
        ActiveChart.SeriesCollection(5).Select
        With Selection.Format.Line
             .Visible = msoTrue
             .Weight = 1.5
        End With
    End If
    

    This will only work if you have exactly 5 series, if you have more then the Count evaluates to say, 6, the above formatting would not be applied.

    You can change the If statement slightly to the following:

    If ActiveChart.SeriesCollection.Count >= 5 Then
    
        ActiveChart.LegEND.LegendEntries(5).Select
        ActiveChart.SeriesCollection(5).Select
        With Selection.Format.Line
             .Visible = msoTrue
             .Weight = 1.5
        End With
    
    End If
    

    You can then repeat this block in your code for >= 6 and it should work. On a side note, this is probably not the most efficient way to code this as you are repeating blocks of code, but that’s not really the point of this question.

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

Sidebar

Related Questions

I'm relatively new to jquery, so I have what I hope will be a
A relatively (I hope) simple jQuery question: I have a menu: <ul id=menu style=list-style:none>
I have a need to run a relatively large number of virtual machines on
I have what should be a relatively simple question that I can't seem to
I hope this is a relatively easy problem although I have spent hours websearching
I have what I hope is a fairly simple question about using the value
I have what I hope is a simple question pertaining to the Atmel AVR
My problem (and solution?) is simple - I hope :) I have a RIA
I'm trying to learn WPF, so here's a simple question, I hope: I have
I hope this is allowed but I have a number of questions regarding Facebook

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.