+ Reply to Thread
Results 1 to 4 of 4

Running Macros on multiple worksheets

Hybrid View

  1. #1
    Registered User
    Join Date
    09-21-2011
    Location
    london, England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Running Macros on multiple worksheets

    Hi,

    i have a macro that is currently performing actions on one worksheet. I have copied this worksheet and named it something slightly different. I now want to edit this macro so that it runs it also performs the same actions on the copied sheet. There are many other worksheets in my workbook but only want this macro to be performed on sheets "LS04" and "LS05" (the names i have assigned the worksheets)

    The code i have running on the the original worksheet is

    
    Sub Addworkstage()
    '
    ' Addworkstage Macro
    'ALLOWS USER TO ADD ADDITIONAL WORK STAGE TO BUILD UP COST ESTIMATE
    
        Application.ScreenUpdating = False
        LS04.Unprotect Password:=LogCode
        Rows("32:49").Select
        Selection.EntireRow.Hidden = False
        Rows("33:48").Select
        Selection.Copy
        Range("A65536").End(xlUp).Offset(0, 0).Select
        Selection.Insert Shift:=xlDown
        ActiveWindow.SmallScroll Down:=18
        Application.CutCopyMode = False
        Rows("33:48").Select
        Selection.EntireRow.Hidden = True
        Range("A50").Select
        
        If AdminAccess = True Then
        LS04.Unprotect Password:=LogCode
        Else
            
        LS04.Protect Password:=LogCode
        Application.ScreenUpdating = True
        
        End If
    End Sub

    Thanks in advance for your help

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Running Macros on multiple worksheets

    You could reset the macro to do it's magic on the "activesheet" instead of any specific named sheet. Assuming your macros are getting called in a controlled manner, that should work, no? If you make the macros PRIVATE they won't show in the Macro list so that should suppress accidental manual activation, then you can put buttons on the sheets where you want the macro to work and call it that way.

    Private Sub AddWorkstage()
    '
    ' Addworkstage Macro
    'ALLOWS USER TO ADD ADDITIONAL WORK STAGE TO BUILD UP COST ESTIMATE
    
    Application.ScreenUpdating = False
    With ActiveSheet
        .Unprotect Password:=LogCode
        .Rows("32:49").EntireRow.Hidden = False
        .Rows("33:48").Copy
        With .Range("A" & .Rows.Count).End(xlUp)
            .Insert Shift:=xlDown
            .Select
        End With
        .Rows("33:48").EntireRow.Hidden = True
    
        If AdminAccess = False Then .Protect Password:=LogCode
    End With
    
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    09-21-2011
    Location
    london, England
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Running Macros on multiple worksheets

    hi JBeaucaire

    Many thanks for your quick response, well the sheet "LS04" is currently in view for the user to input information, "LS05" is a copy of LS04 and is hidden from view, therefore when the user inputs information it is linked with LS05 and copies information across and is not meant to be seen by the user. The issue is that the user can add a set of cells (using the above macro) in LS04 and input extra information and therefore this will not be captured into the copied sheet (LS05). This is why i want the same actions performed on both sheets. Essentially i want any action on LS04 mirrored on LS05.

    Thanks
    Last edited by shivrklfc; 10-30-2012 at 10:43 AM.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Running Macros on multiple worksheets

    you can't add a second duplicate set of code into your macro to mimic the same actions on another sheet?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1