Running a macro on multiple

Last Edited By Krjb Donovan
Last Updated: Mar 05, 2014 09:53 PM GMT

Question

I am not familiar with Macros as all but I have established a macro to perform a sort on certain columns and rows. I want the macro to run on several worksheets (not all) within the same workbook that the macro is located. How do I accomplish this? I am working in Excel 2007 and I'm not if I need to put the code on each individual sheet or how this can be done. Here is my macro.

Sub auto_open()


'auto_open Macro

'ActiveWorksheet.Save


CutCopyMode = False

Range("A15:fj100").sort Key1:=Range("e15"), Order1:=xlAscending, Header:=xlGuess, _

OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBot_

DataOption1:=xlSortNormal


End Sub

Thank you for your time.

Answer

Are you sure you want the line ActiveWorksheet.Save commented? this means it is not running as code.

Here is the revised sub:

Sub auto_open() 'auto_open Macro

'ActiveWorksheet.Save

CutCopyMode = False

With Worksheets("Sheet1")

   .Range("A15:fj100").Sort Key1:=Range("e15"), Order1:=xlAscending, Header:=xlGuess, _
       OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBot_
       DataOption1:=xlSortNormal

End With

With Worksheets("Sheet2")

   .Range("A15:fj100").Sort Key1:=Range("e15"), Order1:=xlAscending, Header:=xlGuess, _
       OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBot_
       DataOption1:=xlSortNormal

End With

'Etc


End Sub

Advertisement

©2022 eLuminary LLC. All rights reserved.