ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem with a defined variable (https://www.excelbanter.com/excel-programming/296350-problem-defined-variable.html)

ric

Problem with a defined variable
 
Hi again,

Heres the code, it works fine till it gets to the last line i've pasted. The
graph was created via recording a macro and replacing the range "C1:AM5"
with "MyRange".


Public MyRange As Range
_________________________

Sub Cumulative_Data()

Sheets("cum_data").Select
Start = 2
t1 = Sheets("cum_data").Cells(Start, 1).Value
t2 = Sheets("cum_data").Cells(Start, 2).Value
TheTitle = t2 & " " & "-" & " " & t1
Fname = t2
Set MyRange = Range("C1:AM5")
MyRange.Select

Call Cum_data_graph

End Sub
_____________________________

Sub Cum_data_graph()
'
' This macro makes a line graph
'
Application.ScreenUpdating = False
Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("cum_data").Range(MyRange),
PlotBy _
:=xlRows



Chip Pearson

Problem with a defined variable
 
Change

ActiveChart.SetSourceData
Source:=Sheets("cum_data").Range(MyRange), PlotBy _
:=xlRows
to
ActiveChart.SetSourceData Source:=MyRange, PlotBy:=xlRows



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"ric" wrote in message
...
Hi again,

Heres the code, it works fine till it gets to the last line

i've pasted. The
graph was created via recording a macro and replacing the range

"C1:AM5"
with "MyRange".


Public MyRange As Range
_________________________

Sub Cumulative_Data()

Sheets("cum_data").Select
Start = 2
t1 = Sheets("cum_data").Cells(Start, 1).Value
t2 = Sheets("cum_data").Cells(Start, 2).Value
TheTitle = t2 & " " & "-" & " " & t1
Fname = t2
Set MyRange = Range("C1:AM5")
MyRange.Select

Call Cum_data_graph

End Sub
_____________________________

Sub Cum_data_graph()
'
' This macro makes a line graph
'
Application.ScreenUpdating = False
Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData

Source:=Sheets("cum_data").Range(MyRange),
PlotBy _
:=xlRows





Tom Ogilvy

Problem with a defined variable
 
Range(myRange) is illegal.

use just

Myrange (with no sheet qualification)

or

Range(Myrange.address)

--
Regards,
Tom Ogilvy


"ric" wrote in message
...
Hi again,

Heres the code, it works fine till it gets to the last line i've pasted.

The
graph was created via recording a macro and replacing the range "C1:AM5"
with "MyRange".


Public MyRange As Range
_________________________

Sub Cumulative_Data()

Sheets("cum_data").Select
Start = 2
t1 = Sheets("cum_data").Cells(Start, 1).Value
t2 = Sheets("cum_data").Cells(Start, 2).Value
TheTitle = t2 & " " & "-" & " " & t1
Fname = t2
Set MyRange = Range("C1:AM5")
MyRange.Select

Call Cum_data_graph

End Sub
_____________________________

Sub Cum_data_graph()
'
' This macro makes a line graph
'
Application.ScreenUpdating = False
Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("cum_data").Range(MyRange),
PlotBy _
:=xlRows






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

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