+ Reply to Thread
Results 1 to 6 of 6

Userform, multiple sets of ToggleButtons, rationalise to single code?

  1. #1
    Registered User
    Join Date
    03-04-2012
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    6

    Userform, multiple sets of ToggleButtons, rationalise to single code?

    Hello

    I have a multipage userform which includes around 50 sets of 3 togglebuttons. Each set of 3 togglebuttons are within a frame and the frame includes a textbox and a label. The 3 toggle buttons are option answers to questions and the user must select one of the three togglebuttons for their answer of 'yes', 'no' or 'not applicable'. On selecting the correct button, the answer is placed into a specific cell on the worksheet.

    I have the following code, which works fine for one set of the buttons:
    Please Login or Register  to view this content.
    Rather than repeat the code 50+ times, could someone point me in the right direction to be able to use the code once in a module (?) and then be able to call that module for each set of the 3 togglebuttons? It may be difficult as each answer is transferred into a non-consecutive cell in the workbook?

    Thank you in advance for any pointers.
    Last edited by poolierob; 09-12-2015 at 08:36 PM. Reason: additional info re frames

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Userform, multiple sets of ToggleButtons, rationalise to single code?

    Why don't you just call a separate piece of code for all and use that to do your stuff.

    For example:
    Please Login or Register  to view this content.
    Please click the * below if this helps

  3. #3
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Userform, multiple sets of ToggleButtons, rationalise to single code?

    Hi
    The way to go when you want to manage large number of virtually the same controls (i.e. they do the same) with single piece of code is to create custom class. Attached is working example that should allow you to expand it as needed, as long as you follow naming conventions for frame and toggle buttons. the result is reflected in column A. In my opinion it's better to have OK button and reflect all changes at the end, but in this case I followed your style i.e. once toggle button is clicked, its value is reflected. And finally, it's better to use radio button controls instead of toggle buttons, as they take care to change the value for the rest of the controls in the group.
    In my example I use consecutive cells to place the answer. You can use Array to store the values or you can put cell address in each frame's tag property at design time
    Attached Files Attached Files
    Last edited by buran; 09-13-2015 at 05:03 AM.
    If you are pleased with a member's answer then use the Star icon to rate it.

  4. #4
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Userform, multiple sets of ToggleButtons, rationalise to single code?

    Actually,
    here is example with non-consecutive target cells for answers
    put worksheet name in Tag property of the UserForm
    put each cell address as Tag property of the respective frame
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    03-04-2012
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Userform, multiple sets of ToggleButtons, rationalise to single code?

    Thank you all for your replies, much appreciated

    I'll try these options and report back !

    Thanks

  6. #6
    Registered User
    Join Date
    03-04-2012
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    6

    Re: Userform, multiple sets of ToggleButtons, rationalise to single code?

    Many thanks to JasperD and buran for your help.

    All solutions worked, and I am going to use buran's non consecutive target cell method as it works best for the worksheet I have inherited.

    Thanks again.

+ 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. [SOLVED] ToggleButtons , lots of togglebuttons.. need to shorten the vba code
    By Aurbo in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-25-2015, 12:19 PM
  2. Replies: 2
    Last Post: 04-15-2013, 08:50 AM
  3. Code to rationalise multiple command buttons in VBA
    By newbi004 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-16-2012, 07:48 AM
  4. How to setup a graph from multiple data sets into a single display
    By pjw23 in forum Excel Charting & Pivots
    Replies: 9
    Last Post: 10-20-2012, 06:03 AM
  5. Replies: 1
    Last Post: 08-02-2012, 03:58 AM
  6. Converting Multiple sets of rows to a single row
    By JuJuBe in forum Excel General
    Replies: 4
    Last Post: 05-11-2012, 10:56 AM
  7. [SOLVED] Togglebuttons as drawers on multiple sheets
    By Claus in forum Excel General
    Replies: 0
    Last Post: 07-05-2005, 03:05 AM

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