Chart source data range

G

Guest

I am trying to add charts where the source data range is variable. The
following code gives me a "91" error "Object variable not set. It does not
like the activecell reference for the range.

How can I get around this problem?

Sub AddChart()
Charts.Add
ActiveChart.ChartType = xl3DColumn
ActiveChart.SetSourceData
Source:=Sheets(myDivision).Range(ActiveCell.Offset(1, 0),
ActiveCell.End(xlDown).Offset(0, 2)), _
PlotBy:=xlColumns

Thank you for your assistanve.

Don
 
T

Tom Ogilvy

Is the activesheet mydivision? Mydivision defined? If not, there's your
huckleberry.

Sub AddChart()
Dim rng as Range
With Sheets(myDivision)
set rng = .Range(.Range("A2"), _
.Range("A2").End(xlDown).Offset(0, 2))
End with
Charts.Add
ActiveChart.ChartType = xl3DColumn
ActiveChart.SetSourceData _ Source:=rng, _
PlotBy:=xlColumns
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Dynamic chart problem 1
Delete a chart 4
Loop to create charts 1
Discontiguous Chart Source 6
having trouble with a chart range 1
Chart Size & Position 3
Range 5
Chart error: plotting series data XY scatter plot 3

Top