Chart within Worksheet

  • Thread starter Thread starter Microsoft
  • Start date Start date
M

Microsoft

I am trying to generate a series of charts on individual worksheets. I have
all of the data in each of the worksheets and then make the graphs. I use
ochart.location where:=xlLocationAsObject Name:=sheetname
I expected the charts to appear within each sheet however they appear on the
same sheet. Is there a way to place each chart on the associated worksheet?
 
How is sheetname defined? Maybe you're looping through the sheets to
create the charts, but define sheetname near the top of your code, so it
doesn't change for each loop.

The following code will create a chart on each worksheet:

Sub CreateCharts()
Dim chObj As ChartObject
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
Set chObj = ws.ChartObjects.Add _
(Left:=100, Width:=400, Top:=100, Height:=250)
chObj.Chart.ChartType = xlLineMarkers
chObj.Chart.SetSourceData _
Source:=ws.Range("A2").CurrentRegion, PlotBy:=xlColumns
Next ws
End Sub
 
Back
Top