View Full Version : Solved: Run two macros from one button

02-01-2008, 06:12 AM
I have two macros in a standared module say named Sub test() and Sub check()

In sheet1, I have attached two command buttons and named command button1 as “Tst” and commandnutton2 as “Chek”
Code for cmdbtn1 is

Private Sub CommandButton1_Click()
Call test
End Sub

Code for cmdbtn2 is
Private Sub CommandButton2_Click()
Call Check
End Sub

I want place one command button on Sheet1
When the btn will be clicked with the caption “Tst” for once it will run “test” and the caption will change to “Chek”
If the caption is “Chek” then run Check and then to change the caption to “tst”

02-01-2008, 07:25 AM
Simon Lloyd has an article in the Knowledge Base that may be what you are looking for: 'Execute different line of code with second click of command button'.

Click to see it: http://vbaexpress.com/kb/getarticle.php?kb_id=940


02-01-2008, 10:58 AM
You could use an if statement to check the caption, and call the appropriate sub:

Private Sub CommandButton1_Click()
If CommandButton1.Caption = "test" Then
call test
CommandButton1.Caption = "Check"
call check
CommandButton1.Caption = "test"
End If
End Sub

02-01-2008, 09:49 PM
Thanks to duo for the reply. Its working.