Results 1 to 4 of 4
  1. #1
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    ChartObject in Excel graph (Office xp, win2000)

    I'm writing a macro to make a Bar Chart.

    Range("A6:C19").select
    charts.add
    ActiveChart.ChartType = xlBarClustered
    ...

    I can't figure out how to size this embedded chart. I've tried set eChart = ActiveSheet.ChartObjects(1).chart
    eChart.Width = 100

    but that seems to be the wrong syntax. What am I doing wrong? Thank you

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: ChartObject in Excel graph (Office xp, win2000)

    You need to treat the Chart as a member of the Shapes collection. The following will increase the width and height by a factor of 1.5 <pre> With ActiveSheet.Shapes("Chart 1")
    .ScaleWidth 1.5, msoFalse
    .ScaleHeight 1.5, msoFalse
    End With</pre>

    or the Following will apply specified dimensions (points, I think)<pre> With ActiveSheet.Shapes("Chart 1")
    .Height = 150
    .Width = 250
    End With</pre>


    Andrew C

  3. #3
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: ChartObject in Excel graph (Office xp, win2000)

    If you create the embedded chart directly, then you can specify the left, top, width, and height directly. Also remember that all of the AddXXX methods return an object, so use a set statement or a with block:
    <pre>Option Explicit
    Sub Macro2()
    Dim co As ChartObject
    Set co = ActiveSheet.ChartObjects.Add(10, 100, 500, 200)
    co.Chart.ChartType = xlBarClustered
    co.Chart.SetSourceData Source:=Sheets("Sheet1").Range("A1:B3")
    End Sub

    Sub Macro3()
    With ActiveSheet.ChartObjects.Add(10, 100, 500, 200)
    .Chart.ChartType = xlBarClustered
    .Chart.SetSourceData Source:=Sheets("Sheet1").Range("A1:B3")
    End With
    End Sub</pre>

    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  4. #4
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Illinois
    Posts
    552
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: ChartObject in Excel graph (Office xp, win2000)

    Thank you so much!

Posting Permissions

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