+ Reply to Thread
Results 1 to 12 of 12

Option buttons in userform

  1. #1
    Forum Contributor
    Join Date
    11-03-2009
    Location
    Florida
    MS-Off Ver
    Excel 365
    Posts
    291

    Option buttons in userform

    This site won't let me post my code for some reason but I think I can describe the situation well enough that someone might be able to help me.

    I have a userform that allows me to fill textboxes with data from a specified row, edit it and write it back. That is working fine.

    Now I want to have 2 option buttons to perform a similar function.
    I have a variable (VOT) that gets data from a specified cell in my database. That data can only be 1 or 2. I want that variable to set button1 or button2 to TRUE.

    Then I want to set another variable (VOTER) to 1 or 2 depending on the final condition of the buttons.

    Your help is most appreciated.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Option buttons in userform

    Hello Len,

    You could upload the workbook to a public file sharing site and post the link to download it.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,914

    Re: Option buttons in userform

    Supposing the value is in Range("A1") and your OptionButtons are called OptionButton1 and OptionButton2 this should answer your first question.

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  4. #4
    Forum Contributor
    Join Date
    11-03-2009
    Location
    Florida
    MS-Off Ver
    Excel 365
    Posts
    291

    Re: Option buttons in userform

    Here is my sample. I want the buttons to be set to VOTER and to make VOTER 1 or 2. VOTER is column AJ in the data. This is to select OWNER1 or OWNER2 as the voter.

    Thanks agian for all your help.
    Attached Files Attached Files

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,914

    Re: Option buttons in userform

    IMHO 30 VlookUp's in your code is overkill but since it works for you I've made the changes to your code for myself (as I would do it). If you're interested I'll post the file for you to compare.
    As for your question. Put this at the end of your CBunit_Change

    Please Login or Register  to view this content.
    and this to substitute the last line in your cmdUPDATE code.

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    11-03-2009
    Location
    Florida
    MS-Off Ver
    Excel 365
    Posts
    291

    Re: Option buttons in userform

    bakerman2, I would be most interested in your code. I am all but illiterate here, everything I've done is by stealing snippets of code that I don't really understand and beating it into submission. I knew this was inelegant at best.

    I did a lot of things that I know were less than best practice.
    For instance, I didn't know how to get the row number, so I made a new column (ROW) and brought it in to an invisible textbox so I could make it a variable.
    I did the same thing with VOTER, I don't need that textbox, it was just the only way I could figure out how to do it.

    And, while you are offering, I would like optionbutton2 to remain false if OWNER 2 LAST NAME (TxtO2LN) is blank.

    THANK YOU, THANK YOU, THANK YOU!
    Last edited by Len Silva; 06-15-2017 at 12:02 PM.

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,914

    Re: Option buttons in userform

    Try this one out and let me know where it might fail.
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    11-03-2009
    Location
    Florida
    MS-Off Ver
    Excel 365
    Posts
    291

    Re: Option buttons in userform

    bakerman2, That is so much better. I cannot thank you enough. I haven't tried it on my live data yet, but it looks fantastic.

  9. #9
    Forum Contributor
    Join Date
    11-03-2009
    Location
    Florida
    MS-Off Ver
    Excel 365
    Posts
    291

    Re: Option buttons in userform

    OK, it works great in your sample, but not in my data. I replaced my code with yours and deleted the ROW column. I did not copy your userform to mine because I don't know how.

    When I update any row, it writes it to row 2 in my data, and the option buttons don't work as in the sample. Could that be changes you made to the form?

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,914

    Re: Option buttons in userform

    First make a copy of your original file and work with that first.
    To replace your userform with mine, open both example file and original file and open VB-Editor.
    In the Project window delete the userform in the original file then drag (select userform and keep left mousebutton down) the userform from the example file to the original file.

  11. #11
    Forum Contributor
    Join Date
    11-03-2009
    Location
    Florida
    MS-Off Ver
    Excel 365
    Posts
    291

    Re: Option buttons in userform

    I was unable to figure out how to copy the userform, but I was able to copy all my original data back into the sample you made and it is working just as I had hoped.
    A million thanks and I will mark this one solved.

  12. #12
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,914

    Re: Option buttons in userform

    Glad you got it working to your wishes.
    Happy to help and thanks for feedback and rep+.

+ 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. Multiple Option Buttons in Userform
    By cmonstuh in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-19-2018, 07:48 AM
  2. Userform option buttons set to false
    By c.davidson in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-02-2016, 04:39 AM
  3. [SOLVED] Option buttons and Image (userform)
    By kasharis in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-07-2014, 07:10 AM
  4. [SOLVED] Option Box buttons in UserForm help
    By motolich in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-28-2013, 12:04 AM
  5. UserForm with option buttons for a survey
    By JimmyG. in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-22-2013, 06:15 AM
  6. Userform Summing Option buttons
    By flebber in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-23-2010, 08:21 AM
  7. Help with a option buttons located in a userform
    By mav93 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-01-2006, 01:40 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