How to make VBA code graphing sheet independent

Help1468

New Member
Joined
Jun 1, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
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!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top