+ Reply to Thread
Results 1 to 9 of 9

Assigning macros to buttons on all worksheets

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-07-2012
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    156

    Assigning macros to buttons on all worksheets

    Time for the experts on this one )

    I have a workbook that contains approximately 100 identical worksheets (including buttons). I want to assign each button on each worksheet to a macro. i tried to do it by selecting a tab and then "Select All Sheets". It seems that "Select All Sheets" deactivates when I right click on the macro button I want to assign a macro to.

    I'd sure appreciate your help. Thanks !!
    Last edited by The Skipper; 02-22-2012 at 08:23 PM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Assigning macros to buttons on all worksheets

    Hi,

    Do the buttons all run the same macro?

    If so why not create a macro to copy the button and then loop through all the sheets and paste it.

    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    02-07-2012
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    156

    Re: Assigning macros to buttons on all worksheets

    Richard~

    I think I misunderstood your question. The answer is yes. I want the buttons on each worksheet to access the same four macros.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Assigning macros to buttons on all worksheets

    Hi,

    That's fine. It doesn't alter the general technique, just copy and paste all four buttons within the loop that progresses through all the sheets.

    Regards

  5. #5
    Forum Contributor
    Join Date
    02-07-2012
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    156

    Re: Assigning macros to buttons on all worksheets

    Please give me a helping hand with the code.

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Assigning macros to buttons on all worksheets

    Hi,

    Assuming this is a Forms Control Button then add your four buttons on Sheet1 and assign them to their macros. Then run the following macro

    Sub CopyFormButton()
       Sub CopyFormButton()
        Dim x As Long, y As Long, stCell
    
        stCell = Array("B5", "B10", "B15", "B20") ' set cell ref for positioning button
    
        
        For x = 2 To Sheets.Count
            Sheets(x).Activate
            For y = 1 To 4
                Sheets("Sheet1").Shapes("button " & y).Copy
                Range(stCell(y - 1)).Select
                ActiveSheet.Paste
            Next y
        Next x
    
    End Sub
    Last edited by Richard Buttrey; 02-22-2012 at 08:12 PM.

  7. #7
    Forum Contributor
    Join Date
    02-07-2012
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    156

    Re: Assigning macros to buttons on all worksheets

    Richard~

    There are 4 buttons on each worksheet, I want to link them to 4 different macros.

    Thanks !!

  8. #8
    Forum Contributor
    Join Date
    02-07-2012
    Location
    US
    MS-Off Ver
    Excel 2007
    Posts
    156

    Re: Assigning macros to buttons on all worksheets

    Thanks Richard..........You're getting 5 starts !!
    Works perfectly.

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Assigning macros to buttons on all worksheets

    Hi,

    Thanks for the rep point.

    Just as an aside, don't forget that you can also use all the drawing shapes as 'buttons'. You don't necessarily need the form or activex buttons.
    I generally prefer these since drawing shapes since they offer more designs and formatting options and generally look smarter and prettier.

    Regards

+ 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