+ Reply to Thread
Results 1 to 9 of 9

Data Labels on Scatter Plot VBA -- Looping through code for each data series

  1. #1
    Registered User
    Join Date
    06-17-2014
    Location
    Columbus, OH
    MS-Off Ver
    2010
    Posts
    9

    Data Labels on Scatter Plot VBA -- Looping through code for each data series

    Hi All!

    VBA rookie here trying to add some data labels to a plot. The code below successfully adds data labels (using values one column to the left of the x-values) to the plot for the first series of data. Does anyone know how I would take this and have it loop through for however many data series are in the plot? I am plotting a table which I plan to apply filters to, so the data will be dynamic and I plan to run the code each time I change the filter so that the labels will update.

    Any help or tips would be very much appreciated! Thanks for reading.

    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Data Labels on Scatter Plot VBA -- Looping through code for each data series

    This free add-in may do what you want.

    The XY Chart Labeler


    Or try something like this (not tested)

    Please Login or Register  to view this content.
    [/B]
    Last edited by AlphaFrog; 01-21-2015 at 10:48 AM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    06-17-2014
    Location
    Columbus, OH
    MS-Off Ver
    2010
    Posts
    9

    Re: Data Labels on Scatter Plot VBA -- Looping through code for each data series

    Add-ins are certainly an option. Thanks for the post Alpha! I'd ideally like to do this without add-ins though so others can use the file without having to download the add-in.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Data Labels on Scatter Plot VBA -- Looping through code for each data series

    Quote Originally Posted by johnctholen View Post
    Add-ins are certainly an option. Thanks for the post Alpha! I'd ideally like to do this without add-ins though so others can use the file without having to download the add-in.
    I added code (untested) to the reply above.

  5. #5
    Registered User
    Join Date
    06-17-2014
    Location
    Columbus, OH
    MS-Off Ver
    2010
    Posts
    9

    Re: Data Labels on Scatter Plot VBA -- Looping through code for each data series

    Thanks so much, that untested formula looks good AlphaFrog! Thanks for the quick response.

    There is an additional issue now though. I am getting "run-time error '5': Invalid procedure call or argument".
    It is occurring at the line highlighted red below and only when I add additional series' (in this case the one titled "Practum") to the plot. I have tried some troubleshooting but cannot for the life of me figure out why this is happening.
    Any ideas??? I attached a sample because I think the problem is with the plot and not the code but I am not sure.


    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    06-17-2014
    Location
    Columbus, OH
    MS-Off Ver
    2010
    Posts
    9

    Re: Data Labels on Scatter Plot VBA -- Looping through code for each data series

    UPDATE:

    I have discovered that the code will only work if I use SERIES NAMES which are 3 characters or less. If any series has a name with more than 3 characters I receive the error above.

    Can anyone help me out here with why this is the case?? Please excuse my limited knowledge of VBA.

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Data Labels on Scatter Plot VBA -- Looping through code for each data series

    Replace this....

    Please Login or Register  to view this content.
    With this...
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-17-2014
    Location
    Columbus, OH
    MS-Off Ver
    2010
    Posts
    9

    Re: Data Labels on Scatter Plot VBA -- Looping through code for each data series

    Thank you so much AlphaFrog!! If you have time and could explain what the problem was with the previous code I would appreciate the learning opportunity. No problem if not. You're a lifesave!

  9. #9
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Data Labels on Scatter Plot VBA -- Looping through code for each data series

    You're welcome.

    Open the Locals window and step through the code. You can see what happens to xVals for each series.

    Debugging VBA Code

    The 14 length argument for the Mid function I think needs to be calculated for different length series names.

+ 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. Add Data Labels to Dynamic Scatter Plot
    By johnctholen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-15-2014, 10:08 AM
  2. Replies: 2
    Last Post: 04-05-2014, 06:46 PM
  3. Replies: 2
    Last Post: 11-11-2013, 05:37 PM
  4. [SOLVED] Scatter Plot Data Labels
    By Mike K. in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 01-22-2008, 10:12 AM
  5. Importing series labels from a column in a scatter plot
    By excelcharter in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 08-22-2006, 05:45 PM

Tags for this Thread

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