Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() 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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
One Chart, Same Data ranges, different source sheets | Charts and Charting in Excel | |||
Change Source Data in VBA | Charts and Charting in Excel | |||
source data from multiple sheets | Charts and Charting in Excel | |||
how to link data from one source sheet to multiple sheets | Excel Worksheet Functions | |||
Change Data Source | Excel Programming |