Hi all,
I am very new to excel VBA so pardon my ignorance. I am trying to graph a set of values in a scatter plot. I have got the code to work on the sheet I made the code on, but if I run it on another sheet it only plots the data from the original sheet. Here is my current code:
Sub GraphStressStrainCurve()
'
' GraphStressStrainCurve Macro
'
' Keyboard Shortcut: Ctrl+Shift+Q
'
Range("O8").Select
ActiveSheet.Shapes.AddChart2(240, xlXYScatterSmoothNoMarkers, 480, 57.5, 432).Select
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = "=""Title"""
ActiveChart.FullSeriesCollection(1).XValues = "='Sheet1'!$E$13:$E$10000"
ActiveChart.FullSeriesCollection(1).Values = "='Sheet1'!$D$13:$D$10000"
ActiveChart.Axes(xlCategory).MinimumScale = 0
ActiveChart.Axes(xlCategory).MaximumScale = 600
ActiveChart.Axes(xlValue).MinimumScale = 0
ActiveChart.Axes(xlValue).MaximumScale = 1
End Sub
I assume the issue is with the part where it calls out 'Sheet 1', but I don't know how to fix it. Ideally the code would just run on whatever sheet I was on. I have read about ActiveSheet, but I don't know how to implement it.
Thanks!
I am very new to excel VBA so pardon my ignorance. I am trying to graph a set of values in a scatter plot. I have got the code to work on the sheet I made the code on, but if I run it on another sheet it only plots the data from the original sheet. Here is my current code:
Sub GraphStressStrainCurve()
'
' GraphStressStrainCurve Macro
'
' Keyboard Shortcut: Ctrl+Shift+Q
'
Range("O8").Select
ActiveSheet.Shapes.AddChart2(240, xlXYScatterSmoothNoMarkers, 480, 57.5, 432).Select
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(1).Name = "=""Title"""
ActiveChart.FullSeriesCollection(1).XValues = "='Sheet1'!$E$13:$E$10000"
ActiveChart.FullSeriesCollection(1).Values = "='Sheet1'!$D$13:$D$10000"
ActiveChart.Axes(xlCategory).MinimumScale = 0
ActiveChart.Axes(xlCategory).MaximumScale = 600
ActiveChart.Axes(xlValue).MinimumScale = 0
ActiveChart.Axes(xlValue).MaximumScale = 1
End Sub
I assume the issue is with the part where it calls out 'Sheet 1', but I don't know how to fix it. Ideally the code would just run on whatever sheet I was on. I have read about ActiveSheet, but I don't know how to implement it.
Thanks!