Execute a Subroutine from a different sheet

  • Hi Guys,


    Just a simple one for you,


    I have my main subroutine in, for example sheet6, and I have a button in sheet1 that when I press I would like the subroutine in sheet6 to execute, how can I do this ?


    Thanks in advance


    Adrian

  • Re: Execute a Subroutine from a different sheet


    Put the macro in a module. Refer to this macro from your sheet and your button.

    Code
    Private Sub Worksheet_Activate()
          Macroname
    End Sub


    And just assign the button to macroname as well.

    [SIZE=2]I should change my name to STUMBED![/SIZE]

  • Re: Execute a Subroutine from a different sheet


    Quote from adetuc

    I have my main subroutine in, for example sheet6, and I have a button in sheet1 that when I press I would like the subroutine in sheet6 to execute, how can I do this ?


    Do you mean the code is in the Sheet6 worksheet code module, if so then use

    Code
    Sheet6.Macro_Name
  • Re: Execute a Subroutine from a different sheet


    It would indeed make more sense to put that code in a standard module.


    ...and then reference the code from the various sheet-coded objects (if necessary).

    [SIZE="1"]Sub All_Macros(Optional control As Variant)[/SIZE]

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!