+ Reply to Thread
Results 1 to 10 of 10

Run a VBA subroutine?

  1. #1
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Run a VBA subroutine?

    I have written some code in Module 2
    When I try and run it either with F5 or from Run; Run Sub/UserForm
    It displays the Macro dialogue box
    My code isn't listed
    How do I run my Sub??
    Help please
    Last edited by barryleajo; 07-23-2010 at 04:48 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Hoe do I run a VBA subroutine?

    Does your routine take any arguments? Did you click inside the routine code before pressing f5?
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Hoe do I run a VBA subroutine?

    Hi Romperstomper
    Many thanks for your quick response
    Yes the routine takes arguments which I have set up just before the Sub...code
    I have even tried putting a Call Sub..... before the Sub code.
    Yes I have put the cursor inside the Sub code to no avail.

    There is no other Subs inside Module 2 in this workbook
    There are other Subs in Module 1 in the same workbook

    The effect is to display the select Macros dialogue box when I try to run it

    There are three Subs (from Module 1) listed in the Selec/Run Macro dialogue
    Tow of these I created using Macro Recorder
    the third I didn't so don't know how or why it appears here
    Confused!!

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Hoe do I run a VBA subroutine?

    If your sub takes arguments, you cannot run it directly - you need another sub that calls that sub and passes the required values to it.

  5. #5
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Hoe do I run a VBA subroutine?

    OK I understand that - thanks
    My problem is before that
    I don't even get into the Run because of the Select Macro dialogue box automatically opening

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Run a VBA subroutine?

    As I said, you can't run that directly. If you try, you will get the macros dialog instead. You need to create another sub that calls your sub. For example:
    Please Login or Register  to view this content.

    If you put the cursor in macro1 and press f5 you will get the select macros dialog. If you put the cursor in Macro2 and press f5 it will run and call macro1.

    Does that help?

  7. #7
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Run a VBA subroutine?

    Got it shg
    Thanks for your patience.
    In fact I REM'd out the arguments and "hardwired" them into the Sub for testing purposes
    It acted just as you have said
    Great and thanks.
    How do I mark this query as Solved?

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Run a VBA subroutine?

    I' m not shg.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  9. #9
    Valued Forum Contributor
    Join Date
    06-19-2010
    Location
    Holywell, N Wales, UK
    MS-Off Ver
    Excel 2013
    Posts
    470

    Re: Run a VBA subroutine?

    Er...how embarrassing and profuse apols
    shg has been responding to me on another query
    Thanks for the advice and I have marked my query as SOLVED

    Just for completeness given that you are a moderator would you mark my previous post "Controlling display position" as SOLVED please.

    If you hadn't responded to me how would I contact a moderator on the forum?

    With thanks romperstomper!!!!

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Run a VBA subroutine?

    See the How To links at the top of this page.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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