View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.charting
Tushar Mehta
 
Posts: n/a
Default Help with macro to assign min and max to x-axis

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

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article , tlobbosNOS-
says...
After a lot of search, I managed to do this:

Sub Macro1()
minim = Range("param!i35").Value2
maxim = Range("param!i45").Value2
ActiveSheet.ChartObjects("Chart 7491").Activate
ActiveChart.Axes(xlCategory).Select
With ActiveChart.Axes(xlCategory)
.MinimumScale = minim
.MaximumScale = maxim
End With
ActiveChart.ChartArea.Select
ActiveWindow.Visible = False
End Sub

The workbook contains many graphs:
- 1 sheet with 1 scatter graph
- 1 sheet with 8 scatter graphs
- 4 sheets with 2 3D-graphs and 23 scatter graphs each
- a couple of sheets without graphs

There are three things I don't know how to do:
1) To assign the same minimum and maximum to the x-axes of
all the scatter graphs in one shot.
2) To change the names of the graphs ("Chart 7491" is awkward).
3) To unselect the graphs after the execution of the macro
(I have to press Escape, or else any movement of the cursor
would drag the graph).

Any help would be much appreciated.