Get Macro on one Worksheet to Work on Others

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The following macro to makes a chart from Sheet foo in a workbook that has 20 Worksheets. Each worksheet is identical with regard to the data, hence the Range command always works.

Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Sheets("foo").Range("B3:B508,E3:E508"), _
PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="foo"
ActiveChart.HasLegend = False

What needs to be done to make this work on all the worksheets in the Workbook.
 
If the sheet to be worked on is the activesheet
Dim sName as String
Dim sh as Worksheet
sName = Activesheet.Name
set sh = activesheet
Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=sh.Range("B3:B508,E3:E508"), _
PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:=sName
ActiveChart.HasLegend = False

--
Regards

Tom Dunlap said:
The following macro to makes a chart from Sheet foo in a workbook that has
20 Worksheets. Each worksheet is identical with regard to the data, hence
the Range command always works.
Charts.Add
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData
Source:=Sheets("foo").Range("B3:B508,E3:E508"), _
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top