Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
OTS
 
Posts: n/a
Default Using macro to run repetitive tasks

Below is a portion of the macro (that I have cropped, original version is
much longer but a lot of this is repetitive statement) that allow me to
change the chart setting for a chart. I intend to change the setting for
about 20 charts in a worksheet

There must be a way to shorten this macro €“ retaining the main body of the
macro but replacing the chart Name (in bold, big fonts) with N then define

N= CHART_1, CHART_2, CHART_3, CHART_4 Etc etc

Let the macro run for CHART_1 until the last CHART and stop there.

By doing so the macro will be shorter and neat.

Question: how to do write a macro for this repetitive task?

Thanks

ActiveWindow.Visible = False
Windows("autoplot.xls").Activate
ActiveSheet.ChartObjects("CHART_1").Activate
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScale = 2000
.MaximumScale = 3000
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
ActiveWindow.Visible = False
Windows("autoplot.xls").Activate
ActiveSheet.ChartObjects("CHART_2").Activate
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScale = 2000
.MaximumScale = 3000
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
ActiveWindow.Visible = False
Windows("autoplot.xls").Activate
ActiveSheet.ChartObjects("CHART_3").Activate
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScale = 2000
.MaximumScale = 3000
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
ActiveWindow.Visible = False
Windows("autoplot.xls").Activate
ActiveSheet.ChartObjects("CHART_4").Activate
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScale = 2000
.MaximumScale = 3000
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With

  #2   Report Post  
Duke Carey
 
Posts: n/a
Default

use something like

Dim cho as ChartObject

For Each cho in ActiveSheet.ChartObjects
cho.activate
--your code here--
Next cho


"OTS" wrote:

Below is a portion of the macro (that I have cropped, original version is
much longer but a lot of this is repetitive statement) that allow me to
change the chart setting for a chart. I intend to change the setting for
about 20 charts in a worksheet

There must be a way to shorten this macro €“ retaining the main body of the
macro but replacing the chart Name (in bold, big fonts) with N then define

N= CHART_1, CHART_2, CHART_3, CHART_4 Etc etc

Let the macro run for CHART_1 until the last CHART and stop there.

By doing so the macro will be shorter and neat.

Question: how to do write a macro for this repetitive task?

Thanks

ActiveWindow.Visible = False
Windows("autoplot.xls").Activate
ActiveSheet.ChartObjects("CHART_1").Activate
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScale = 2000
.MaximumScale = 3000
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
ActiveWindow.Visible = False
Windows("autoplot.xls").Activate
ActiveSheet.ChartObjects("CHART_2").Activate
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScale = 2000
.MaximumScale = 3000
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
ActiveWindow.Visible = False
Windows("autoplot.xls").Activate
ActiveSheet.ChartObjects("CHART_3").Activate
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScale = 2000
.MaximumScale = 3000
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
ActiveWindow.Visible = False
Windows("autoplot.xls").Activate
ActiveSheet.ChartObjects("CHART_4").Activate
ActiveChart.Axes(xlValue).Select
With ActiveChart.Axes(xlValue)
.MinimumScale = 2000
.MaximumScale = 3000
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With

Reply
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
Macro -- repetitive tasks OTS Excel Discussion (Misc queries) 1 October 7th 05 04:23 PM
Macro - message box if find nothing Frantic Excel-er Excel Discussion (Misc queries) 8 July 1st 05 08:45 PM
Help with macro looping and color query function kevinm Excel Discussion (Misc queries) 10 May 26th 05 01:25 AM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM


All times are GMT +1. The time now is 10:09 AM.

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

About Us

"It's about Microsoft Excel"