+ Reply to Thread
Results 1 to 14 of 14

Dynamic Name for "Chart" in VBA

  1. #1
    Registered User
    Join Date
    10-05-2004
    Location
    Scarborough, ON
    MS-Off Ver
    Mac Office 2019 v16.30 (19101301)
    Posts
    69

    Dynamic Name for "Chart" in VBA

    Morning All,

    Please Login or Register  to view this content.
    using a macro to create a chart but noticed that the static names prevents me from testing it over and over again.

    also this code refers to the part where i re-size the chart to fit the printable area.

    any ideas?

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,462

    Re: Dynamic Name for "Chart" in VBA

    If there is only 1 chart on the worksheet then

    Please Login or Register  to view this content.
    If you create the chart with VBA then give it a meaningful name via code.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    10-05-2004
    Location
    Scarborough, ON
    MS-Off Ver
    Mac Office 2019 v16.30 (19101301)
    Posts
    69

    Re: Dynamic Name for "Chart" in VBA

    thx for the code

    need 2 more things:
    1. how to name chart in vba code
    2. how to delete that chart

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,462

    Re: Dynamic Name for "Chart" in VBA

    How do you add the chart? Show us your code.

  5. #5
    Registered User
    Join Date
    10-05-2004
    Location
    Scarborough, ON
    MS-Off Ver
    Mac Office 2019 v16.30 (19101301)
    Posts
    69

    Re: Dynamic Name for "Chart" in VBA

    i took the code straight from "record macro"

    Please Login or Register  to view this content.
    i made the adjustment - removed Shapes("Chart 5") and replaced with ChartObjects(1)
    Last edited by hemants; 12-21-2010 at 11:07 AM.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,462

    Re: Dynamic Name for "Chart" in VBA

    Something like the following,

    Give the activechart's parent a fixed name.
    Please Login or Register  to view this content.
    delete a chart with that fixed name
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    10-05-2004
    Location
    Scarborough, ON
    MS-Off Ver
    Mac Office 2019 v16.30 (19101301)
    Posts
    69

    Re: Dynamic Name for "Chart" in VBA

    thx Andy Pope,

    you adjust work perfectly with my existing code but now I run into a new problem

    getting a runtime error 1004 at the beginning of the following code

    Please Login or Register  to view this content.
    any way to adjust the code?

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,462

    Re: Dynamic Name for "Chart" in VBA

    Does series 1 have data labels that you can select?

    Selection of elements in a chart is not normally required.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-05-2004
    Location
    Scarborough, ON
    MS-Off Ver
    Mac Office 2019 v16.30 (19101301)
    Posts
    69

    Re: Dynamic Name for "Chart" in VBA

    yes, when selecting the range values the heading for each field is as follows

    Cable - would be considered SeriesCollection(1)
    DSL - would be considered SeriesCollection(2)
    Dial - would be considered SeriesCollection(3)

  10. #10
    Registered User
    Join Date
    10-05-2004
    Location
    Scarborough, ON
    MS-Off Ver
    Mac Office 2019 v16.30 (19101301)
    Posts
    69

    Re: Dynamic Name for "Chart" in VBA

    Quote Originally Posted by Andy Pope View Post
    Does series 1 have data labels that you can select?

    Selection of elements in a chart is not normally required.

    Please Login or Register  to view this content.
    i get errored out on the above line when running those commands

  11. #11
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,462

    Re: Dynamic Name for "Chart" in VBA

    when selecting the range values
    You mention range values. The code suggests selection of data labels. If the data labels do not exists, and there is no code to suggest they do, you will not be able to select them.

    Can you post example workbook?

  12. #12
    Registered User
    Join Date
    10-05-2004
    Location
    Scarborough, ON
    MS-Off Ver
    Mac Office 2019 v16.30 (19101301)
    Posts
    69

    Re: Dynamic Name for "Chart" in VBA

    Hi Andy,

    i excluded some secure info and just provided the sheets that are being used

    VBA code is in the "Control" Sheet
    Chart info is in the "Data" Sheet
    Chat location is in "BiWeekly Pg8" Sheet

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

  13. #13
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,462

    Re: Dynamic Name for "Chart" in VBA

    As I said previously you can not select data labels unless you have applied data labels. You code does not apply datalabels.

    you need to add a line to apply them

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    10-05-2004
    Location
    Scarborough, ON
    MS-Off Ver
    Mac Office 2019 v16.30 (19101301)
    Posts
    69

    Re: Dynamic Name for "Chart" in VBA

    Hi Andy,

    that line was exactly what I needed to make the macro work

    ActiveChart.ApplyDataLabels

    it runs through properly with no runtime error

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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