Ref Commandbutton

  • Thread starter Thread starter WLMPilot
  • Start date Start date
W

WLMPilot

I have a workbook with several sheets pertaining to my work schedule,
paychecks, stats, etc. On each sheet, I have a command button for sheet so I
can click on the button and change sheets. Thus, I have several command
buttons that reference one sheet.

Is there a way to have these command buttons reference one set of code so
that I only have to enter the code to change to that sheet once?

Thanks,
Les
 
Put your common code in a standard module. Your various button macros can
reference the common code:

Sub Button2_Click()
Call master
End Sub


Sub master()
MsgBox (" ")
End Sub
 
Is the "standard module" the same as "ThisWorkbook" in the Microsoft Excel
Object window?

Les
 
Thought of another question after I responded to your last reply.

I am use to creating a commandbutton on individual sheets that change by the
numeric value, ie cmdbutton1,2,3, etc. and therefore reference the subroutine
for its respective commandbutton1,2,3. If I place the code in the standard
module, how do I get the various "like" commandbuttons on different sheets to
point to that code? I may have commandbutton2 and commandbutton 4 on
different sheets (with there on individual code) but they both do the
samething, which is to switch to the STATS sheet.

Thanks,
Les
 
Please forgive my last post. It was early in the morning when I read your
answer and brain was not working. This is what I tried:

I changed the code for the commandbutton that changes to STATS sheet to

FROM:
Private Sub CommandButton4_Click()
Application.Goto Reference:=Worksheets("STATS").Range("A1")
End Sub

TO:
Sub CommandButton4_Click()
'Call Stats
End Sub

I placed the following code in the "ThisWorkbook" module

Sub Stats()
Application.Goto Reference:=Worksheets("STATS").Range("A1")
End Sub


I get a "Sub or Function not defined" compile error.

LEs
 
Back
Top