ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA code problem (https://www.excelbanter.com/excel-programming/303262-vba-code-problem.html)

excelnoob[_2_]

VBA code problem
 
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 Whe=xlLocationAsObject, Name:="sheet2"

And this one does?

Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceDat
Source:=Sheets("sheet1").Range("C49:E61")PlotBy :=xlColumns
ActiveChart.Location Whe=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

--
Message posted from http://www.ExcelForum.com


Don Guillett[_4_]

VBA code problem
 
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)


--
Don Guillett
SalesAid Software

"excelnoob " wrote in message
...
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.SetSourceData
Source:=Sheets("sheet1").Range(Range("C37").Offset (Range("C33"), 0),
Range("C37").Offset(Range("D33"), 2)), PlotBy :=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:="sheet2"

And this one does?

Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData
Source:=Sheets("sheet1").Range("C49:E61")PlotBy :=xlColumns
ActiveChart.Location Whe=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 creating
the chart that works in example 1?

Thank you for your help


---
Message posted from
http://www.ExcelForum.com/





All times are GMT +1. The time now is 01:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com