+ Reply to Thread
Results 1 to 5 of 5

Use command button more then once

  1. #1
    Registered User
    Join Date
    12-08-2017
    Location
    Nederland
    MS-Off Ver
    Microsoft Office Professionel Plus 10
    Posts
    42

    Use command button more then once

    Hi,

    I have some simple macro's who I want to start with a click on a command button. When I click on the button he has to run macro1, and when I click again on the same button he has to run macro2 and so on.

    Is it possible to run more then one macro after a click on the same button?

    When I use my code he runs both maco's after clicking on the button

    Sub macro1()
    Dim Get_Value As Variant
    Range("A1").Select
    Range("A1").Value = Range("E1").Value
    End Sub
    Sub macro2()
    Dim setValue_Var As Range
    Range("A2").Select
    Range("A2").Value = Range("E2").Value
    End Sub
    Sub CommandButton1_Click()
    Call macro1
    Call macro2
    End Sub

    Thanks,
    Costertje

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Use command button more then once

    Assuming you are not using a userform, you can try with a global variable 'remembering' whether you've clicked, and it'll keep alternating between macro1 and 2.
    Please Login or Register  to view this content.
    多么想要告诉你 我好喜欢你

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,909

    Re: Use command button more then once

    In ThisWorbook module.

    Please Login or Register  to view this content.
    In Standard module.

    Please Login or Register  to view this content.
    In Sheet module (CommandButton code)

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Registered User
    Join Date
    12-08-2017
    Location
    Nederland
    MS-Off Ver
    Microsoft Office Professionel Plus 10
    Posts
    42

    Re: Use command button more then once

    Hi,

    Thanks for the answers. I've used the code Bakerman2, because that's working fine and I can expand this with more clicks.

    Costertje

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,909

    Re: Use command button more then once

    You're welcome.

    You may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given.
    By doing so you can add to the reputation(s) of those who helped.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Copying ActiveX Command Button from master sheet to subsheets. command button code missing
    By popper08 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-13-2020, 10:15 AM
  2. Replies: 2
    Last Post: 02-02-2016, 10:27 PM
  3. Insert Command Button that will Activate Command Button on a Different Sheet
    By realvirtuality1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-06-2016, 02:11 PM
  4. VBA code to create command button. Print all sheets then delete command button.
    By Declamatory in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-15-2015, 05:18 PM
  5. Make a Command Button Visible from another Command Button
    By trevor2524 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-13-2014, 10:11 AM
  6. Replies: 1
    Last Post: 09-17-2007, 09:57 PM
  7. Replies: 0
    Last Post: 11-03-2005, 11:00 AM

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