Consulting

Results 1 to 4 of 4

Thread: Change the position and size of the Pie Chart

  1. #1

    Change the position and size of the Pie Chart

    In excel, how can change the position and size of a pie VBA generated chart with VBA code.

    Basically I wanted to create 7 charts based on the raw data in the same worksheet. There is no problem on creating the charts by using Charts.Add method in VBA, but once the chart has been created, I couldn?t change the position and the size of them via VBA code because I don?t know the name of those charts and failed to find it from Excel manual.

    It seems excel would give a object name automatically when a chart object has been created.
    I've been stucked for the whole day and couldn't find a solution. Thanks very much for your time and help.

  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Hi there,

    My first stop when I'm playing with Charts is Jon Peltier's site. This article specifically deals with moving and resizing charts using VBA.

    HTH,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    This might get you started....from a post by Jake-seems they are numbered according to the order on the sheet. Someone correct me if I'm wrong.

    Sub x()
    ActiveSheet.ChartObjects(2).Cut
    Sheets("Sheet2").Select
    Range("B5").Select
    ActiveSheet.Paste
    End Sub
    will move the second chart to sheet 2 range B5
    Last edited by Aussiebear; 04-21-2023 at 07:13 PM. Reason: Adjusted the code tags
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    Quote Originally Posted by lucas
    This might get you started....from a post by Jake-seems they are numbered according to the order on the sheet. Someone correct me if I'm wrong.
    Interesting... I would have thought they would be numbered according to the order they were created, although I have no empirical evidence to support this. It just would make sense, or inserting a new chart above an existing one would break all the VBA code done...

    I guess either is possible...
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





Posting Permissions

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