Placing charts within a sheet

S Haspel

New Member
Joined
Jan 23, 2006
Messages
46
I'm running a macro which is creating a series of charts and am trying to get the code to place them.

Is there a line of code which lets you define the top left corner point or anything? I'm using .Parent.Width and .Parent.Height to define the size. Is there a Parent.Location or .Parent.Address which lets me specify the co-ordinates?


Regards
Simon
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Bartek

Board Regular
Joined
Jul 29, 2006
Messages
54
Hi,

Is there a line of code which lets you define the top left corner point or anything? I'm using .Parent.Width and .Parent.Height to define the size. Is there a Parent.Location or .Parent.Address which lets me specify the co-ordinates?

Any object like Cell or Shape has its Top and Left coordinates. You may use something like this:

Code:
With ActiveSheet.ChartObjects("Chart 1")
 .Top = 100
 .Left = 100
End With
 

SydneyGeek

MrExcel MVP
Joined
Aug 5, 2003
Messages
12,251
This code lets you position a chart so it covers cells B12:G24 inclusive --
Code:
Sub Macro2()
    Dim sglHeight As Single
    Dim sglWidth As Single
    Dim sglTop As Single
    Dim sglLeft As Single

    sglTop = Range("B12").Top
    sglLeft = Range("B12").Left
    sglHeight = Range("B25").Top - Range("B12").Top
    sglWidth = Range("H12").Left - Range("B12").Left
    
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.ChartArea.Select
    With ActiveSheet.Shapes("Chart 1")
        .Top = sglTop
        .Left = sglLeft
        .Height = sglHeight
        .Width = sglWidth
    End With
End Sub
Denis
 

Watch MrExcel Video

Forum statistics

Threads
1,111,599
Messages
5,541,166
Members
410,543
Latest member
ExcelGlenn
Top