LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Change source data to all sheets


I have defined various name ranges and I use them in a macro to create
a chart it works fine for sheet 1. But i want to use the same dynamic
range for all sheets in the workbook.

So basically what i want is a macro to run through my workbook and
create a chart, for the data in the defined range, on every worksheet
(excluding the worksheet titled "Master").


Code:
--------------------

Sub addChart()
Dim myChart As Excel.Chart

'add chart
Set myChart = Charts.Add
'set chart type for e.g. xlPie,xlLine,xlArea,xl3DColumn etc
ActiveChart.ApplyCustomType ChartType:=xlUserDefined, TypeName:= _
"Cumulative or Comparative"
'set data range
myChart.SetSourceData Source:=Range("mediaeq"), PlotBy:=xlColumns
'Turn on the major gridlines for both axes
myChart.Axes(xlCategory).HasMajorGridlines = False
myChart.Axes(xlValue).HasMajorGridlines = False
ActiveChart.SeriesCollection(1).XValues = Range("programs")
ActiveChart.SeriesCollection(1).Values = Range("mediaeq")
'Turn on the Legend and position it on top of the chart
myChart.HasLegend = False
'Show values on the bars of the chart
myChart.ApplyDataLabels xlDataLabelsShowValue
'Finally, which sheet you want the chart on
myChart.Location xlLocationAsObject, "Sheet1" 'This adds a standard sized chart to sheet2, but if you want to add a
' new sheet with just chart on it, replace the above line with next line...
'myChart.Location xlLocationAsNewSheet, "Mychartsheet"
'If you want specify the height and width of the chart object.......
ActiveSheet.Shapes(ActiveChart.Parent.Name).ScaleW idth 0.7, msoFalse, msoScaleFromTopLeft
ActiveSheet.Shapes(ActiveChart.Parent.Name).ScaleH eight 0.7, msoFalse, msoScaleFromTopLeft

Set myChart = Nothing
End Sub

--------------------


--
Vlad999
------------------------------------------------------------------------
Vlad999's Profile: http://www.excelforum.com/member.php...o&userid=33586
View this thread: http://www.excelforum.com/showthread...hreadid=546321

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
One Chart, Same Data ranges, different source sheets Greg in CO[_2_] Charts and Charting in Excel 4 March 12th 10 02:57 PM
Change Source Data in VBA Risky Dave Charts and Charting in Excel 1 November 9th 09 02:38 PM
source data from multiple sheets JNW Charts and Charting in Excel 3 June 24th 07 02:41 PM
how to link data from one source sheet to multiple sheets Ashish Deshmukh Excel Worksheet Functions 2 June 15th 07 04:08 PM
Change Data Source Alfred[_3_] Excel Programming 3 September 21st 04 07:41 AM


All times are GMT +1. The time now is 08:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"