Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.charting
|
|||
|
|||
![]()
Tushar Mehta wrote:
Addressing your requests in reverse order... Usually there is no need to select and/or activate objects. Iterating through a collection with the For...Each loop removes the need to id individual objects. The For...Each loop also lets one go through each object in a collection. In this case, there are two collections that need to be addressed. The sheets in a workbook and the chartobjects in a sheet. The code below addresses all three of your concerns: Option Explicit Option Base 0 Sub doOneChart(aChart As Chart) With aChart.Axes(xlCategory) .MinimumScale = Range("param!i35").Value2 .MaximumScale = Range("param!i45").Value2 End With End Sub Sub FixAllChartsInActiveWorkbook() Dim aSheet As Object, aChartObj As ChartObject For Each aSheet In ActiveWorkbook.Sheets If TypeOf aSheet Is Chart Then doOneChart aSheet If TypeOf aSheet Is Chart Or TypeOf aSheet Is Worksheet Then For Each aChartObj In aSheet.ChartObjects doOneChart aChartObj.Chart Next aChartObj End If Next aSheet End Sub I am grateful to you all for your prompt reply. The variation to Jerry's code introduced by Andy is, in effect, necessary. Tushar's macro stops executing when it gets to the 3D-charts. On the other hand, only Tushar's macro tries executing in all sheets. So I have a mix of the two: Sub Macro1() minim = Range("param!i35").Value2 maxim = Range("param!i45").Value2 For Each aSheet In ActiveWorkbook.Sheets For Each ch In aSheet.ChartObjects Select Case ch.Chart.ChartType Case xlXYScatter, xlXYScatterLines, xlXYScatterLinesNoMarkers, _ xlXYScatterSmooth, xlXYScatterSmoothNoMarkers With ch.Chart.Axes(xlCategory) .MinimumScale = minim .MaximumScale = maxim End With End Select Next ch Next aSheet End Sub And it works ... too well. But that's my fault. I had overlooked the fact that 33 of the scatter graphs (11 in 3 sheets) have dates on the x-axis, and must not be modified. I am sorry about that. So how do I exclude them from macro execution ? Two ways come to my mind: - modify their type and exclude the type. I am referring to the types mentioned in the code above (which I don't understand): xlXYScatter, xlXYScatterLines, xlXYScatterLinesNoMarkers, xlXYScatterSmooth, xlXYScatterSmoothNoMarkers - exclude them by name. In any case, I wouldn't know how to do it and still need help. What about modifying a chart's name ? |