+ Reply to Thread
Results 1 to 14 of 14

Fill a textbox with varaible text depending on Radio Button selection combo

  1. #1
    Registered User
    Join Date
    10-26-2015
    Location
    San Diego
    MS-Off Ver
    ALL
    Posts
    12

    Fill a textbox with varaible text depending on Radio Button selection combo

    Hi All,

    I need some help with getting the right code to do the following:

    * I have 4 groups of radio buttons inside a frame in a userform
    * Each group is a simple Yes/No radio button
    * I have a textbox that I want to autofill with a score range of A-D depending on the # of "yes" radio buttons selected.
    * The "No" checkboxes really shouldn't do anything in regards to the textbox

    Userform Name = TP_UF
    Frame Name = fun_opt_frame
    Option Button Name for "Yes" = fun_score_yes1
    Textbox Name = fun_scorebox

    Logic:
    4 Yesses = A
    3 Yesses = B
    2 Yesses = C
    1 Yes = D

    It doesn't matter what order the yesses are selected, its a total count. I tried using code using the frame but not sure if that is the best way. The frame for these radio buttons isn't needed for any reason other then to perhaps make it easier to code. So I could throw out the frame if it's not necessary to get this working.

    I am not sure where to start here. Any help would be appreciated.

    radio text.jpg

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Fill a textbox with varaible text depending on Radio Button selection combo

    Hi,
    You look through all the OptionButton controls in the form and if the caption is Yes and the value is True (that means selected) you increase the counter by one
    That's really all there is to it.
    Otherwise attach the file with the userform
    Last edited by Keebellah; 08-26-2018 at 03:42 PM. Reason: Extra info
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Registered User
    Join Date
    10-26-2015
    Location
    San Diego
    MS-Off Ver
    ALL
    Posts
    12

    Re: Fill a textbox with varaible text depending on Radio Button selection combo

    Hi Keebellah,

    Thank you for your response. I understand that the behavior is simple but I am don't know vba very well and I am not sure where to get started. Would it be possible for you to provide some sample code?

    I am playing around with this code but it currently isn't working. When I have a 4 "yes" radio buttons nothing appears in the textbox

    Please Login or Register  to view this content.
    then I will just repeat this code for each score. I am sure there is a better way to go about this.

    Cheers!
    April

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Fill a textbox with varaible text depending on Radio Button selection combo

    Hi April, can you attach your file? Please? will make it easier to modify and show than writing my own

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Fill a textbox with varaible text depending on Radio Button selection combo

    Something like this?
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    10-26-2015
    Location
    San Diego
    MS-Off Ver
    ALL
    Posts
    12

    Re: Fill a textbox with varaible text depending on Radio Button selection combo

    Hi Keebellah,

    Yes this is what I am looking for except when excel counts the number I want the textbox to display A-D with each count (See Below). Also, sorry for not attaching my spreadsheet, I am unable to publish the entire notebook due to propriety data instead. For me to publish the parts i need help with I would have to create a new notebook and pull out just the elements I need to post It takes a lot of work to do. But I don't mind if it helps get me the help I need. I ended up creating a new notebook to post but I saw you created one already. Thank you for this.

    So how I can tell excel that when the counter = 1 then textbox = D, counter = 2, textbox = C, counter = 3, textbox = B, counter = 4, textbox = A

    I am playing with the code to try. I may require another variable as string? Again, forgive me, very new to vba

    Cheers
    April

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Fill a textbox with varaible text depending on Radio Button selection combo

    If you make a copy of your file and remove all the propietary info and replace it with representative dummy data and explain it with that will make it easier to understand.
    VBA is not at all that difficult

  8. #8
    Registered User
    Join Date
    10-26-2015
    Location
    San Diego
    MS-Off Ver
    ALL
    Posts
    12

    Re: Fill a textbox with varaible text depending on Radio Button selection combo

    Hi Keebellah,

    What representative data are you looking for? There isn't any "data" I am simply trying to count the number of "yesses" and assign a letter based on that count. I know it may seem like VBA is easy for you but it doesn't come easily to me and its why I am reaching out for help. I can attach my sample spreadsheet for you but it will look just like yours except it's empty. Can we work of yours and see how we can assign a letter to the count of the data? I am not seeing a way to assign a letter to the count based off the way you used the code. Should I use the textbox itself to convert the number to a letter? If you must have the sample worksheet I will attach it when I get home.

    Thanks
    April

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Fill a textbox with varaible text depending on Radio Button selection combo

    Like this then?

    Good-night
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    10-26-2015
    Location
    San Diego
    MS-Off Ver
    ALL
    Posts
    12

    Thumbs up Re: Fill a textbox with varaible text depending on Radio Button selection combo - SOLVED

    Hi Keebellah!

    Yes! This is it! Viewing the code I see what you added, however, I am not sure how the code is working. I will study it so I can learn from this experience. Thank you so much for working with me.

    Cheers & Goodnight!
    April

  11. #11
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Fill a textbox with varaible text depending on Radio Button selection combo

    Tip: try to read the code as you would a paragraph in a book.
    All it does is check the option buttons, the odd number are the yes ones so that is why the loop x is from 1 to 8 and Ik the step is 2, which means the first x = 1 the next x is not 1 step but 2 , then x= 3 and if the option was selected the value of this button is True this the counter is upped 1
    The final is using the Choose() function which determines the end result

  12. #12
    Registered User
    Join Date
    10-26-2015
    Location
    San Diego
    MS-Off Ver
    ALL
    Posts
    12

    Re: Fill a textbox with varaible text depending on Radio Button selection combo

    Thanks Keebellah, Super helpful tip. I never thought of vba as reading a book.

  13. #13
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Fill a textbox with varaible text depending on Radio Button selection combo

    IT came to me one day when somebody asked me to explain it

  14. #14
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Fill a textbox with varaible text depending on Radio Button selection combo

    Hi,
    If you have lots of OptionButton[s] using a class would be a good option to reduce the code.
    In the Userform-Count-Yes workbook
    Userform Module Code:
    Please Login or Register  to view this content.
    in Class Module Called RadioCount
    Please Login or Register  to view this content.
    Last edited by pike; 08-29-2018 at 08:08 AM. Reason: remove mCaption
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

+ 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] how to fill specific colors of combo box depending on its text values
    By ecuaton in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 06-16-2016, 11:30 AM
  2. [SOLVED] Populating combo box with different lists depending on Option Button selection
    By HeyInKy in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-26-2014, 07:17 PM
  3. [SOLVED] Swap out text in text box based on radio button selection
    By gordco in forum Excel General
    Replies: 2
    Last Post: 12-13-2012, 11:49 AM
  4. Replies: 0
    Last Post: 12-06-2012, 02:52 PM
  5. [SOLVED] Fill a cell via textbox on userform depending on combobox selection
    By Rhamilton2512 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-15-2012, 10:29 AM
  6. [SOLVED] Highlight the contain of textbox and radio button
    By Peter Cheang in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-11-2006, 11:55 AM
  7. checkbox / radio button or combo-box???
    By ko6ad in forum Excel General
    Replies: 1
    Last Post: 02-11-2006, 10:40 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