+ Reply to Thread
Results 1 to 7 of 7

How to make button in user form call a module

  1. #1
    Registered User
    Join Date
    04-05-2008
    Posts
    17

    Question How to make button in user form call a module

    I have three modules, each of which sorts the Excel chart using different columns. I have created a user form that has four buttons. The first three are supposed to call each of the three modules. The last one closes the user form.

    I cannot figure out the very simple task of how to call each of the modules (the Close button works fine). I have been using the book "Excel Programming" by Jinger Simon, but the author does not explain this very necessary and common procedure.

    So two questions: One, how can I call a macro by clicking a button in a user form? Two, are there any good books that explain VBA for Excel?

    Thanks,
    Tom

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    As you can close your form I assume you know haw to attach code to a macro button

    To have your button macro call another macro use
    the command of

    Please Login or Register  to view this content.
    or you can leave the call part of the command out and just use the macro name

    Please Login or Register  to view this content.
    I prefer to use the Call statement as it makes it easier for me when debugging.
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Registered User
    Join Date
    04-05-2008
    Posts
    17

    Thanks

    Your code worked, thanks!
    Tom

  4. #4
    Registered User
    Join Date
    08-08-2012
    Location
    Chicago IL
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: How to make button in user form call a module

    Quote Originally Posted by mudraker View Post
    To have your button macro call another macro use
    the command of

    Please Login or Register  to view this content.
    mudraker,

    I am trying to do the same thing, but when I try to run it, the program is giving me a compile error: "expected variable or procedure, not module" What am I doing wrong?

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: How to make button in user form call a module

    you gave the module and macro the same name. rename one or the other.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  6. #6
    Registered User
    Join Date
    08-08-2012
    Location
    Chicago IL
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: How to make button in user form call a module

    Thank you! Dumb mistake!

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: How to make button in user form call a module

    Akaron, for future reference,

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ 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