+ Reply to Thread
Results 1 to 11 of 11

Same code for 26 Buttons

  1. #1
    Registered User
    Join Date
    07-02-2019
    Location
    Mexico
    MS-Off Ver
    365
    Posts
    7

    Question Same code for 26 Buttons

    Hello everybody, thank you for reading, i'm new at this forum. Hope i can help to somebody sometime.

    Now i have a quiestion.
    I have a form with 26 buttons each one has a letter as a caption, ej. A,B,C,D and so on, I use them for call a function that performs a search with the caption as a variable.
    So the code for the 26 buttons is the same except for de caption.

    Please Login or Register  to view this content.
    is there a way to use just one function or routine that perform this? i do not want to have the same code for 26 buttons. I want some like this


    Please Login or Register  to view this content.
    Hope this quiestion helps any body else, thank you for reading
    Last edited by Pepe Le Mokko; 07-04-2019 at 11:45 AM.

  2. #2
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Same code for 26 Buttons

    this was posted here a while back and offers a probable solution
    see attached workbook for multiple controls run by class

    In Userform
    Please Login or Register  to view this content.
    in class module called button handler
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by nigelog; 07-04-2019 at 11:24 AM.

  3. #3
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Same code for 26 Buttons

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    I did it for you this time - Please take a moment to read the forum rules

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,078

    Re: Same code for 26 Buttons

    Similar, but deals with existing buttons.
    Create a new Class module & call it CBtns and add this code
    Please Login or Register  to view this content.
    In your Userform module put
    Please Login or Register  to view this content.
    The line in red must go at the very top of the module, before any code

  5. #5
    Registered User
    Join Date
    07-02-2019
    Location
    Mexico
    MS-Off Ver
    365
    Posts
    7

    Re: Same code for 26 Buttons

    oH,, I Think both answers will help me a lot. Thankyou both

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,078

    Re: Same code for 26 Buttons

    You're welcome & thanks for the feedback

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,516

    Re: Same code for 26 Buttons

    Instead of 26 Buttons, how about selecting from a listbox? (See attached)

  8. #8
    Registered User
    Join Date
    07-02-2019
    Location
    Mexico
    MS-Off Ver
    365
    Posts
    7

    Re: Same code for 26 Buttons

    it Works Perfectly !!!! thank you !!

  9. #9
    Registered User
    Join Date
    07-02-2019
    Location
    Mexico
    MS-Off Ver
    365
    Posts
    7

    Re: Same code for 26 Buttons

    It does the job, thats another way. I will keep in mind, i will use your idea on another form. it really help me
    thank you very much.

  10. #10
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,516

    Re: Same code for 26 Buttons

    Glad you can at least use it in the future.
    Good Luck

  11. #11
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Same code for 26 Buttons

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a relatively new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macros with buttons, spin buttons, scroll buttons, etc.
    By qqbbppdd in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-12-2013, 09:34 AM
  2. Useform Code - 12 Command Buttons dependant on other command buttons
    By darrenkaye in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-20-2013, 10:58 AM
  3. assigning code to buttons
    By crazyhick in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-28-2010, 08:02 AM
  4. assigning code to buttons
    By crazyhick in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-28-2010, 06:36 AM
  5. Generic protect/unprotect code through buttons and code?
    By StargateFanFromWork in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-02-2006, 03:35 PM
  6. [SOLVED] Buttons click in Code
    By Bettergains in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-09-2005, 07:05 PM

Tags for this Thread

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