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 7808323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:06:19+00:00 2026-06-02T03:06:19+00:00

I need to create one chart per sheet in Excel. Here is my code:

  • 0

I need to create one chart per sheet in Excel. Here is my code:

    Sheets(i).Activate

    For Each cht In ActiveSheet.ChartObjects
        cht.Delete
    Next

    'create chart
    Set chtChart = ActiveSheet.ChartObjects.Add(Left:=75, Width:=300, Top:=75, Height:=300).Chart
    With chtChart
        .ChartType = xlXYScatterSmooth

        Do While .SeriesCollection.Count <> 0
            Do Until .SeriesCollection.Count = 0
                .SeriesCollection(1).Delete
            Loop
        Loop

        Set srsNew = .SeriesCollection.NewSeries
        With srsNew
            .XValues = "='" & Sheets(i).Name & "'!" & _
            Sheets(i).Range(Range("K2"), Range("k2").End(xlDown)).Address
            .Values = "='" & Sheets(i).Name & "'!" & _
            Sheets(i).Range(Range("l2"), Range("l2").End(xlDown)).Address
        End With
    End With

For the first sheet this works but for the second, third … it does not. It issues the error 1004 “application defined or object defined error” in XValues or Values. I also noticed that if I introduce

range("K2")

outside the with block I get an error in the second, third …. sheets but not in the first one.

Any advise is most welcome

Regards

João

  • 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-02T03:06:20+00:00Added an answer on June 2, 2026 at 3:06 am
    1. Qualify your Ranges with sheets they belong to.
    2. Don’t use Select or ActiveSheet.
    3. Don’t build up the string address. Use ranges directly.
    Dim CurSheet As Worksheet, cht As ChartObject
    Dim chtChart As Chart, srsNew As Series
    
    ...
    
    Set CurSheet = Worksheets(i)
    
    For Each cht In CurSheet.ChartObjects
      cht.Delete
    Next
    
    
    'create chart
    Set chtChart = CurSheet.ChartObjects.Add(Left:=75, Width:=300, Top:=75, Height:=300).Chart
    With chtChart
      .ChartType = xlXYScatterSmooth
    
      Do While .SeriesCollection.Count <> 0
        .SeriesCollection(1).Delete
      Loop
    
      Set srsNew = .SeriesCollection.NewSeries
      With srsNew
        .XValues = CurSheet.Range(CurSheet.Range("k2"), CurSheet.Range("k2").End(xlDown))
        .Values = CurSheet.Range(CurSheet.Range("l2"), CurSheet.Range("l2").End(xlDown))
      End With
    End With
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a chart in excel in a delphi application based on
I need to create one list based on two other lists. But seems like
I need to create more than one UIView with MARQUEE effect like HTML <marquee>
I need to create a stored proc that will return records (more than one
I need to create a single trace file that spans several days for one
I need to create a batch file that reads a file with one line
I need to create and combine several expressions for child entity into one to
I have a one-time need to create a file from an iOS mutable array.
I need to create a data.frame that will be populated one row at a
I need to create a web app for a client, and one of the

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.