-
Solved: Run two macros from one button
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
[vba]
Private Sub CommandButton1_Click()
Call test
End Sub
[/vba]
Code for cmdbtn2 is
[vba]Private Sub CommandButton2_Click()
Call Check
End Sub [/vba]
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”
-
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
Ron
-
You could use an if statement to check the caption, and call the appropriate sub:
[VBA]
Private Sub CommandButton1_Click()
If CommandButton1.Caption = "test" Then
call test
CommandButton1.Caption = "Check"
Else
call check
CommandButton1.Caption = "test"
End If
End Sub[/VBA]
-
Thanks to duo for the reply. Its working.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules