ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Charts in VBA (https://www.excelbanter.com/excel-programming/335495-charts-vba.html)

Rui Álvares

Charts in VBA
 
Hi,

I have the code shown below, that creates a chart based in the data present
in sheet "Sheet_1":

Charts.Add
ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SetSourceData Source:= _
Sheets("Sheet_1").Range("A1:B382"), PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:="Grafics"
With ActiveChart

FcoMariscal

Charts in VBA
 
You need to be sure you are using the proper Sheet Object
better change to this
with Sheets("Sheet_1")
.Range(.Cells(1, 1), .Cells(rowNum, 2)),
PlotBy:=xlColumns
end with


Beware of the point before the Cells methods, indicating that you are
refering to the same sheet.

Francisco mariscal

"Rui Ãlvares" wrote:

Hi,

I have the code shown below, that creates a chart based in the data present
in sheet "Sheet_1":

Charts.Add
ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SetSourceData Source:= _
Sheets("Sheet_1").Range("A1:B382"), PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:="Grafics"
With ActiveChart
.
. (the code positioned here don't interest for the case)
.
End With
ActiveSheet.Shapes("Chart 2").ScaleHeight 1.25, msoFalse,
msoScaleFromBottomRight

This code runs perfectly, but if I change the fourth line for the given line
(rowNum is an integar variable):

Sheets("Sheet_1").Range(Cells(1, 1), Cells(rowNum, 2)),
PlotBy:=xlColumns

the program crashes. I don't understand why this happens because in the VBA
help I found
range defined in this form. The same happesn if I change the variable rowNum
for an integer number.
Have you any idea toresolve this problem?

Thanks in advance

Rui






All times are GMT +1. The time now is 03:06 PM.

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