+ Reply to Thread
Results 1 to 5 of 5

The chart shows what it wasn't programmed for

  1. #1
    Registered User
    Join Date
    03-07-2024
    Location
    Czech Republic
    MS-Off Ver
    Microsoft 365 MSO
    Posts
    3

    The chart shows what it wasn't programmed for

    I'm trying to create a chart for evaluating my measurements, but for some reason when I run the code the generated chart decides to show some random data sets (orange and grey shouldnt be there). As in the picture below.
    Sn?mek obrazovky 2024-03-07 103944.png

    Here is the VBA code:
    VBA code.txt

    Could you please tell me where's the problem? I'm pretty inexperienced and I just don't see it.
    Last edited by komixek; 03-07-2024 at 06:11 AM.

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064

    Re: The chart shows what it wasn't programmed for

    Isn't the loop that says "Add random points" doing this?

    The orange lines have 5 points
    The grey lines have 5 points

    That's the loop that goes from 2 to 6 (5 different steps)

    Just delete that loop from the VBA
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: The chart shows what it wasn't programmed for

    The active cell is within your data set so when you add the chart it uses the data surrounding the selected cell. Clear all the series after creating the chart, then add the ones you want to see. Or select a cell nowhere near the data before adding the chart.
    Rory

  4. #4
    Registered User
    Join Date
    03-07-2024
    Location
    Czech Republic
    MS-Off Ver
    Microsoft 365 MSO
    Posts
    3

    Re: The chart shows what it wasn't programmed for

    I tried to play a little with it and it seems like the problem is in this: Set chrt = ws.Shapes.AddChart2(-1, xlXYScatterLines).Chart
    It probably automaticaly generates chart with some number it has available (apparently VBA doesn't care that you haven't satated the values which are supposed to be in the chart).

    Here's the code without adding any data sests to the chart:
    Please Login or Register  to view this content.
    Is there a way how to force VBA to not auto-include data sets? Or how to exclude some date sets from the chart?
    Last edited by komixek; 03-07-2024 at 09:20 AM.

  5. #5
    Registered User
    Join Date
    03-07-2024
    Location
    Czech Republic
    MS-Off Ver
    Microsoft 365 MSO
    Posts
    3

    Re: The chart shows what it wasn't programmed for

    That was the problem. Thank you so much.

    Just for the record here's the final code.
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Pie Chart that also shows a % within each slice
    By polotoniumx in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 02-26-2019, 04:56 AM
  2. [SOLVED] Need a chart that shows X out of Y totals and %
    By SMITH.CRYSTAL in forum Excel Charting & Pivots
    Replies: 8
    Last Post: 08-12-2015, 04:46 PM
  3. Replies: 11
    Last Post: 06-16-2015, 11:16 AM
  4. [SOLVED] Bar Chart shows total in same Bar
    By turist in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 10-21-2013, 10:58 AM
  5. #Value! shows in text box on top of chart until clicked on
    By socalboarder in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 08-29-2013, 12:44 PM
  6. Replies: 1
    Last Post: 06-20-2013, 01:14 PM
  7. [SOLVED] Error; chart wasn't found
    By Metin in forum Excel General
    Replies: 1
    Last Post: 02-24-2005, 10:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1