+ Reply to Thread
Results 1 to 6 of 6

Make an optionbutton class

  1. #1
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Akron, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    208

    Make an optionbutton class

    I'm working on an Excel 2016 workbook in which there are 10 worksheets each with a series of 4 x 10 option buttons.
    Each worksheet is independent of the others and each set of 10 option buttons are independent of the other 30 option buttons.
    Furthermore, each column of data is independent of the other 9 columns.

    Excel with option buttons.jpg

    I'm hoping for a way to reduce having to program each option button for each column, for each worksheet.
    All I need to do when an option button in a column (the option buttons are grouped in each colunm) is selected is
    run some code to show specific rows.

    I was thinking about making an option button class, but could not find an example of such.

    Do you think that would work? Do you have or know where an option button class example is located?

    Thanks,
    Jeff
    Last edited by jrdnoland; 10-02-2020 at 06:01 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Make an optionbutton class

    Here is an example using command buttons on a userform that can be adapted to any other kind of control. I think the same principles should apply to controls on a worksheet. It is designed as a demo so based on the fact that you are familiar enough with VBA to be asking about a class, this may be sufficient. Let me know if you need more explanation.

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Make an optionbutton class

    You don’t need a class, use regular controls on the worksheet, not activex and just adding the same macro to them all

  4. #4
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Akron, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Make an optionbutton class

    Both great answers, will explore both. Thank you for taking the time to help me!

  5. #5
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Akron, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Make an optionbutton class

    OK, so I tried the class version and can't get it to work.
    This is in my Class
    Please Login or Register  to view this content.
    This is in my module
    Please Login or Register  to view this content.
    This is in my userform2
    Please Login or Register  to view this content.
    When I compile it i get an error message stating: "Object does not source automation events"

    Also, I won't be using a userform, I'll be using a worksheet to hold the option buttons.

    What am I missing?

  6. #6
    Forum Contributor
    Join Date
    12-02-2009
    Location
    Akron, Ohio
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Make an optionbutton class

    Anyone have an Idea on how to fix this?

    Finallly got this to work. Here's what I did. I made the class also parse the incoming button name.
    Each of the four (groups of 10) buttons have either ST, EA,RR, or NS in their names.

    Made a class called clsWSCtls
    Please Login or Register  to view this content.
    Then I made a standfard code module for each one of the buttons, as in modOptButtST. The standard module also handles the
    differences in the set of 10 worksheets, In this case I'm working with the R1 worksheet:

    Please Login or Register  to view this content.
    Finally I put the following code in the Activate event of each workbook:
    Please Login or Register  to view this content.
    The reason I went with the class approach rather than using form buttons with a similar macro was that I couldn't figure out a way to bold the text of the form optionbuttons.
    Last edited by jrdnoland; 10-02-2020 at 06:04 AM.

+ 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. HELP: Make a class schedule
    By Batwarrior in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-20-2017, 02:15 AM
  2. Replies: 17
    Last Post: 11-16-2016, 01:46 AM
  3. “= 1st class’ lower class limit + class width"
    By CheeseFace in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2016, 08:21 PM
  4. Userform - make sure optionbutton and listbox has values
    By Masun in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-04-2013, 07:40 AM
  5. How to make a class module work
    By Bishonen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-05-2012, 12:05 PM
  6. Make VBA Class Module Library
    By Mark Olsen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-26-2006, 07:10 PM
  7. Error 1004: Select method of OptionButton class failed
    By jrubin in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-10-2005, 08:51 PM

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