NonExcelGuru
New Member
- Joined
- Nov 20, 2012
- Messages
- 2
I am writing a macro to create an xy-scatter plot. I have selected the range that I wish to plot. I have several series that I would like to be included in the plot (the specific number of series will vary each time and the number of points). I am having trouble with the activechart.setsourcedata and how to properly set it up, so that the range includes all of the data that I have highlighted. Thanks!
Here is my code:
Sub PlotPureSpectra()
'
' PlotPureSpectra Macro
' Plots Pure Spectra
'
' Keyboard Shortcut: Ctrl+Shift+P
'
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A19").Select
ActiveCell.FormulaR1C1 = "0"
Range("B19").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R3C3+R2C3"
Range("A19:B19").Select
Selection.AutoFill Destination:=Range("A19:B2021")
Range("A19:B2021").Select
Rows("1:1").Select
Selection.Copy
Rows("19:19").Select
Selection.Insert Shift:=xlDown
Range("B19").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SetSourceData Source:=Range("!$B$19:$AJ$2022")
ActiveChart.PlotArea.Select
ActiveChart.ChartArea.Select
Application.CutCopyMode = False
ActiveChart.Location Where:=xlLocationAsNewSheet
End Sub
Here is my code:
Sub PlotPureSpectra()
'
' PlotPureSpectra Macro
' Plots Pure Spectra
'
' Keyboard Shortcut: Ctrl+Shift+P
'
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A19").Select
ActiveCell.FormulaR1C1 = "0"
Range("B19").Select
ActiveCell.FormulaR1C1 = "=RC[-1]*R3C3+R2C3"
Range("A19:B19").Select
Selection.AutoFill Destination:=Range("A19:B2021")
Range("A19:B2021").Select
Rows("1:1").Select
Selection.Copy
Rows("19:19").Select
Selection.Insert Shift:=xlDown
Range("B19").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SetSourceData Source:=Range("!$B$19:$AJ$2022")
ActiveChart.PlotArea.Select
ActiveChart.ChartArea.Select
Application.CutCopyMode = False
ActiveChart.Location Where:=xlLocationAsNewSheet
End Sub