View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
sebastienm sebastienm is offline
external usenet poster
 
Posts: 694
Default Place chart at specific cell location

Hi
When the chart is in a Worksheet you have to move the Chart container
(PArent) which is a ChartObject object. So, say the chart is the #1 on the
active sheet:
'---------------------------------------
Sub test()
With ActiveSheet
.ChartObjects(1).Top = .Range("B2").Top
.ChartObjects(1).Left = .Range("B2").Left
End With
End Sub
'---------------------------------------

Now based on the ActiveChart, you would do something like
'-----------------------------------------------------
Sub test2()
With ActiveChart.Parent 'ie With ChartObject
.Top = .PArent.Range("B2").Top ' ie ActiveChart.Parent.Parent=Worksheet
.Left = .PArent.Range("B2").Left
End With
End Sub
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Landmine" wrote:

I would like to find a method to place a chart at a specific cell location
within a worksheet. I am adding a chart using data within the spreadsheet
and need to place the chart next to the data. I can't seem to find a method.

The code I am using to add the sheet is as follows and I would like to place
the top left hand corner in cell J2.

Thanks
BLandmine

sName = ActiveSheet.Name
Set sh = ActiveSheet
Charts.Add
ActiveChart.ChartType = xlColumnClustered
ActiveChart.SetSourceData Source:=sh.Range("B3:C12"), _
PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:=sName
ActiveChart.HasLegend = False