How to conditionally run 2 macros alternatively one after another? RRS feed

  • Question

  • I have one Macros Which searches for Value in column A and gives result in column B and then deletes column A leaving only the result, This macros is assigned to Button 1, and a second macro which clears the result and Inserts the column A back and formats the cells as required, This macro is assigned to Button 2, Every thing works fine, but if I press the Button 2 twice an extra column gets added. How do I stop this Button from being pressed twice, I want both buttons to be operate able alternatively. Meaning If I run the 2nd macro I want it to be able to run only after I run the first macro and vice versa.
    Thursday, January 30, 2014 5:38 AM

All replies

  • Hi,

    You will have to define global variable.

    For example if Button 1 is connected to macro1 and button 2 is connected to macro2 then in your code

    Option Explicit

    Dim PressButton As Long

    Sub Macro1()

    MsgBox "Last Operation " & PressButton

    End Sub

    Sub Macro2()

    MsgBox "Last Operation " & PressButton

    End Sub

    Guy Zommer

    Sunday, February 2, 2014 2:59 PM