VBA code problem

E

excelnoob

Please help me. I'm banging my head against the wall with this one
Range C33 is 12 and D33 is 24, both are variables

Why this one doesn't work? the prolem is with the data source

Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceDat
Source:=Sheets("sheet1").Range(Range("C37").Offset(Range("C33"), 0)
Range("C37").Offset(Range("D33"), 2)), PlotBy :=xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="sheet2"

And this one does?

Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceDat
Source:=Sheets("sheet1").Range("C49:E61")PlotBy :=xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="sheet2"


The chart source area is this:

Range(Range("C37").Offset(Range("C33"), 0)
Range("C37").Offset(Range("D33"), 2))

This works fine in example 1:

Range(Range("C37").Offset(Range("C33"), 0)
Range("C37").Offset(Range("D33"), 2)).Select
With Selection.Interior
.ColorIndex = 5
.Pattern = xlSolid
End With

So my question is why the same area defining doesn't work in creatin
the chart that works in example 1?

Thank you for your hel
 
D

Don Guillett

Untested but try adding the sheet to your second part of the range.
or use something like
x=1st range
y=2nd range
source=range(x&":"&y)
 
Top