+ Reply to Thread
Results 1 to 5 of 5

Thread: Create A chart Via Macro

  1. #1
    Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2010
    Posts
    132

    Create A chart Via Macro

    I want to be able to create a chart via macro. I can do that ok. The trouble is when I use the macro to create another chart, it uses the data from the last chart. I selected the data before recording the macro thinking that it wouldn't record preselected cells. It seems it does.
    Any ideas of how to overcome this?
    Thanks
    Last edited by Philb1; 09-14-2011 at 07:12 PM. Reason: Solved

  2. #2
    Forum Guru mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2007/2010
    Posts
    3,004

    Re: Create A chart Via Macro

    Have a look at the code that you have recorded and replace the characters which specify the range that you are plotting with the word Selection.

    Suggest posting a copy of the recorded code if you need further help.
    Martin

    Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.

    If my solution has saved you time and/or money, please consider donating to Cancer Research UK.

  3. #3
    Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2010
    Posts
    132

    Re: Create A chart Via Macro

    Hi mrice
    I've attached a file showing the symptoms. Cntrl M runs the macro
    I've no idea what I'm looking for when in the edit screen
    Thanks
    Attached Files Attached Files

  4. #4
    Forum Guru mrice's Avatar
    Join Date
    06-22-2004
    Location
    Surrey, England
    MS-Off Ver
    Excel 2007/2010
    Posts
    3,004

    Re: Create A chart Via Macro

    Try

    Set MyPlotRange = Selection
    ActiveSheet.Shapes.AddChart.Select
        ActiveChart.ChartType = xlCylinderColClustered
        ActiveChart.SetSourceData Source:=MyPlotRange 
        ActiveChart.Parent.Cut
        Sheets("Sheet2").Select
        Range("D4").Select
        ActiveSheet.Paste
        Range("C4").Select
    Martin

    Eighty Twenty Spreadsheet Automation http://homepage.ntlworld.com/martin.rice1/ for all your Excel customisation and consulting needs.

    If my solution has saved you time and/or money, please consider donating to Cancer Research UK.

  5. #5
    Forum Contributor
    Join Date
    08-22-2011
    Location
    Auckland
    MS-Off Ver
    Excel 2010
    Posts
    132

    Re: Create A chart Via Macro

    Thanks Martin. Works a treat. I have another question, but I'll start another thread for it.
    Cheers

+ 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.2.0