vjay
Computer
- Nov 20, 2002
- 2
In Excel, when creating a Macro to plot a chart, the follwoing code was recorded.
Sub PlotGraph2()
'
' PlotGraph2 Macro
' Macro recorded 13/05/2002 by Vasantha Jayasinghe
'
' Keyboard Shortcut: Ctrl+g
'
Sheets.Add
Range("B9".Select
Charts.Add
ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SetSourceData Source:=Sheets("Sheet1".Range("B9", PlotBy:= _
xlColumns
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=IOLevel!R22C2:R31C2"
ActiveChart.SeriesCollection(1).Values = "=IOLevel!R22C7:R31C7"
ActiveChart.SeriesCollection(1).Name = "=""Valve"""
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
End Sub
In here, the name of the worksheet that contain data is 'IOLevel'. Always the column numbers that I want to chart are the same (eg. column 2 for x values and column 7 for y values). Start and end row numbers may change.I want to input the start and finish row numbers to the macro as variables (instead of hardcoded rows 22 and 31) and then construct the ranges for XValues and Values and substitute them in the above macro.
Can someone please advise me how to pass the range information constructed using row numbers inputed by the user and fixed column numbers, to following line.
ActiveChart.SeriesCollection(1).XValues = "=IOLevel!R22C2:R31C2"
Thanks very much.
Vasantha
Sub PlotGraph2()
'
' PlotGraph2 Macro
' Macro recorded 13/05/2002 by Vasantha Jayasinghe
'
' Keyboard Shortcut: Ctrl+g
'
Sheets.Add
Range("B9".Select
Charts.Add
ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SetSourceData Source:=Sheets("Sheet1".Range("B9", PlotBy:= _
xlColumns
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).XValues = "=IOLevel!R22C2:R31C2"
ActiveChart.SeriesCollection(1).Values = "=IOLevel!R22C7:R31C7"
ActiveChart.SeriesCollection(1).Name = "=""Valve"""
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
End Sub
In here, the name of the worksheet that contain data is 'IOLevel'. Always the column numbers that I want to chart are the same (eg. column 2 for x values and column 7 for y values). Start and end row numbers may change.I want to input the start and finish row numbers to the macro as variables (instead of hardcoded rows 22 and 31) and then construct the ranges for XValues and Values and substitute them in the above macro.
Can someone please advise me how to pass the range information constructed using row numbers inputed by the user and fixed column numbers, to following line.
ActiveChart.SeriesCollection(1).XValues = "=IOLevel!R22C2:R31C2"
Thanks very much.
Vasantha