+ Reply to Thread
Results 1 to 7 of 7

Link Chart Name to Cell Value

  1. #1
    Registered User
    Join Date
    11-20-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    29

    Link Chart Name to Cell Value

    Hey guys. I am trying to get familiar with VBA and I got stuck on this problem. I have a macro that will insert a line of data on sheet1, and then make a graph of that data on sheet2. However, when I run this macro a second time I get an error regarding the name of the second chart it created. Long story short: I need a way to use a value from the row a created as a name for the new chart. Despite much searching, I have only been able to find a way link a cell value to a chart title, not the name.

    I am currently using:

    ActiveChart.Parent.Name = "Chart Title"

    But I need for every chart to have a unique name and I cannot find a way to:

    ActiveChart.Parent.Name = "cell value". I have tried ActiveChart.Parent.Name = "=Bills!$A$3" as a test, but (as I am sure you know) it named the chart '=Bills!$A$3'.

    Thanks for all the advice!
    Last edited by exceln00b22; 01-20-2013 at 01:35 PM. Reason: Solved!

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Link Chart Name to Cell Value

    You are extremely close!

    Please Login or Register  to view this content.
    Gary's Student

  3. #3
    Registered User
    Join Date
    11-20-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Link Chart Name to Cell Value

    Perfect! Thank you! But maybe you can help me one more time. I need help generalizing the Range("A3").Value. When the first chart is added I will need:

    Sheets("Bills").Range("A3").Value

    But when the second chart is added I will need:

    Sheets("Bills").Range("A4").Value

    And so on. I already have a counter variable, N, so I tried Sheets("Bills").Range("A" & N).Value, but I was unsuccessful.

  4. #4
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Link Chart Name to Cell Value

    There is nothing wrong with the line of code you posted, I would have to see more of your code to guess why it is not working.

  5. #5
    Registered User
    Join Date
    11-20-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Link Chart Name to Cell Value

    I am sorry if I was unclear. Your code worked great. It was exactly what I was looking for. However, I am not wanting every chart to take their name from A3. I do want the first chart to be named A3, but I would like the second chart generated to pull its name from A4.

    Code:

    (Macro to create row of data on sheet1) then:

    Sheets("Graphs").Select
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
    ActiveChart.Parent.Name = Sheets("Bills").Range("A3").Value

    I am trying to find a way to replace 'Range("A3")' so that it will correspond with where the line on sheet1 was just added. Does that make sense?

  6. #6
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Link Chart Name to Cell Value

    I don't see where you are setting or trying to use the variable N.

  7. #7
    Registered User
    Join Date
    11-20-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    29

    Re: Link Chart Name to Cell Value

    Im sorry. You are exactly right. When I went back to get the code for you, I noticed a typo. Your help has been great! Thanks again!

+ 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