Assign Macro RRS feed

  • Question

  • I have a button in my workbook that called for a macro, but I want to the button to
    check the value typed in B8 and call for macro1 if is A and macro2 if is B and
    so on. Is there any way to do it?

    Fernando Salgueiro

    Thursday, May 14, 2015 10:06 PM


  • Hello Fernando,

    Try the following code to run when the button is clicked.

    If you have used an AxtiveX button control then the sub name will be somewhat different but the actual code that runs will be the same.

    Sub Button1_Click()
        'Ucase is used in next line so that it does not matter if
        'cell B8 contains lower case or upper case character
        Select Case UCase(Range("B8").Value)
            Case "A"    'Use uppercase for all case comparisons
                Call Macro1
            Case "B"
                Call Macro2
            Case "C"
                Call Macro3
        End Select
    End Sub

    Regards, OssieMac

    Sunday, May 17, 2015 6:10 AM