+ Reply to Thread
Results 1 to 7 of 7

Having a master commandbutton "click" another button on a different worksheet

Hybrid View

kuraitori Having a master commandbutton... 10-22-2008, 05:45 PM
jasoncw The first thing you need to... 10-22-2008, 05:57 PM
shg It would be better practice... 10-22-2008, 06:13 PM
kuraitori I do I make something a... 10-22-2008, 06:23 PM
shg In a code module, create two... 10-22-2008, 07:21 PM
kuraitori Thank you so much 10-23-2008, 01:55 PM
kuraitori Name of sheets? 10-22-2008, 06:20 PM
  1. #1
    Forum Contributor
    Join Date
    10-17-2008
    Location
    Vancouver
    MS-Off Ver
    2002 and XP
    Posts
    117

    Having a master commandbutton "click" another button on a different worksheet

    Hello All

    Running into this issue of "transworksheet macros"

    I have a master "update" commandbutton on sheet 1. I have two sub "update" buttons on sheet 2 and 3 respectively.

    What I would like to do is have the user click the master button, that would "click" the two sub buttons so they run their respective macros on their respective worksheets (within the same worksheet.

    I have tried pasting the macro code in the master button, telling it to select the sub worksheet and then run the macro, but the marco runs itself on the master worksheet instead.

    I tried to use the .goto function, but I don't think I know the proper syntax to make that work.

    I have posted the code below with the line I think I need help with in bold.

    Private Sub CommandButton2_Click()
    ' populate Monthly Clinician Summary Macro
     Application.Goto Sheets("MonthlyClinicianSummary").Range("C11:C5000")
        Range("C11:C5000").Copy Destination:=Range("A55400")
        Range("A55398:A60398").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
        Range("A55399:A56296").Copy Destination:=Range("A55299")
        Application.CutCopyMode = False
        With Range("A55300:A55397").Font
            .Name = "Arial"
            .FontStyle = "Regular"
            .Size = 10
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
        Selection.Interior.ColorIndex = xlNone
        Range("A55302").Select

  2. #2
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    The first thing you need to do is remove "Private" from buttons 2 and 3. Then, to call them, you can use:

    Call Sheet2.CommandButton2_Click
    Call Sheet3.CommandButton3_Click
    Be sure to use the correct sheet and command button names.

    HTH

    Jason

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    It would be better practice for the button code to call a routine in a code module to do the processing. That routine could be called by any other.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Contributor
    Join Date
    10-17-2008
    Location
    Vancouver
    MS-Off Ver
    2002 and XP
    Posts
    117
    Quote Originally Posted by shg View Post
    It would be better practice for the button code to call a routine in a code module to do the processing. That routine could be called by any other.
    I do I make something a routine?

    And also, in the master button, how do I specify which worksheet ("sub" worksheet) that I want the routine to run on?

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    In a code module, create two routines, say, Sub Btn1(), and Sub Btn2(), and move all the existing button code to one or the other as appropriate.

    In the click event for one of the buttons, call one of the subs

    In the click event for the other, call the other

    In the click event for the master, call one and then the other.

  6. #6
    Forum Contributor
    Join Date
    10-17-2008
    Location
    Vancouver
    MS-Off Ver
    2002 and XP
    Posts
    117

    Thank you so much

    took me a while to find the module screen. but it works beautifully.

    Thank you so much.

  7. #7
    Forum Contributor
    Join Date
    10-17-2008
    Location
    Vancouver
    MS-Off Ver
    2002 and XP
    Posts
    117

    Name of sheets?

    According to VBA editor the sub button is on sheet 2, commandbutton2,
    so I used that

    Excel gives following prompt

    Run-time Error 1004
    Application-defined orobject-defined error
    So do I use the name I've labeled the sheet?

    If so, what is the syntax?

    Call Sheets("MySheet").CommandButton2_Click
    If so, then I get the
    Select method of range class failed
    error.

    Please advise

+ 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