+ Reply to Thread
Results 1 to 6 of 6

Option Buttons on Userforms

  1. #1
    Registered User
    Join Date
    11-30-2012
    Location
    North Carolina
    MS-Off Ver
    Office 365
    Posts
    61

    Option Buttons on Userforms

    I have two sets of option buttons on a user form.

    Once all the userform data is entered, the user clicks a command button to save the data. I using code similar to the following to copy the data to a separate worksheet (this code works fine):

    Please Login or Register  to view this content.
    The options buttons have a "New" or "Used" captions in the first set and "Yes" or "No" in the second set. I thought i could just save one answer for each option set with the following:

    Please Login or Register  to view this content.
    However, this only produces a blank cell when the copy code is executed:

    .Cells(curRow, 8).value = Me.ActiveCell.value

    Can anyone set me straight or am i pursuing something that isn't possible?

    Thanks.

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

    Re: Option Buttons on Userforms

    How is the ActiveCell becoming active? Is there a flow where the user selects a cell then the form operates on the active cell? It is a better practice to address cells explicitly rather than depend on what is active.

    Also, what is Me intended to be? Where is this line of code?
    Please Login or Register  to view this content.
    Also I'm wondering why you are copying the caption to one cell, then copying that cell to yet another cell.

    This will go a lot faster if you can attach your file.
    Last edited by 6StringJazzer; 03-28-2020 at 06:22 PM.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    11-30-2012
    Location
    North Carolina
    MS-Off Ver
    Office 365
    Posts
    61

    Re: Option Buttons on Userforms

    The premise is that new data will be entered in the top half of a form. The data is saved to a separate worksheet.

    There is a listbox on the form that will permit subsequent editing of the data; the data is pulled into the listbox from the spreadsheet. This issue is based on the Vehicles userform (Step 6 from the menu).

    The vehicles sheet found at the back of the workbook.
    Attached Files Attached Files

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,877

    Re: Option Buttons on Userforms

    I will take a look but be aware that this line of code won't work
    Please Login or Register  to view this content.
    )
    It must be
    Please Login or Register  to view this content.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,877

    Re: Option Buttons on Userforms

    I don't understand where you want to save the option button selection. It seems that Forms!A1 is the active cell when this code is reached. The value "New" is in fact in that cell.

    However, I still don't understand why you want to use that as an intermediate destination when you could load it directly to the final destination cell. I can't figure out where that is supposed to be, because the line of code you showed above does not exist in your project
    Please Login or Register  to view this content.
    It looks like sheet Vehicles columns I and J store the value of these buttons as True and False. I can see nowhere that you would store New/Used.

    If you explain where this value is to be stored then I can help straighten it out.

  6. #6
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Option Buttons on Userforms

    Hi,

    You are very close.

    You have a couple of small physical design issues:
    a. Without any data (in the design) one OptionButton in each Group should be set to 'True'. It does not matter which OptionButton.
    This can be done in the UserForm itself:
    1. Go to VBA and Press key 'F4' to display the Properties Window
    2. Display the UserForm
    3. Left Click on an Option Button
    4. In the Properties Window assign a GroupName. All OptionButtons in the same GroupName behave as a set.

    or can be done during initialization of the UserForm: e.g. VehicleForm.Opt_New = True

    b. the Yes/No OptionButtons have the same 'Group Name' ('NeworUsed') as the New/Used OptionButtons. They behave separately because you have a Frame Around them (which is perfectly fine). It is probably a good idea to rename the Group that contains the 'Yes/No'OptionButtons. You can then remove the 'Frame' if you want.

    c. After you fix 'a.' above, your existing Code for 'One OptionButton' is all you need:
    .Cells(curRow, 9).value = Me.Opt_New.value

    d. Not related. You might want to consider hiding the 'row Number' as a Column in the ListBox. Since you have more than 10 Columns 'Original Row Number' would have to be a Column in the Spreadsheet.

    When reading data into the UserForm:
    Me.Opt_New.value = Me.lstVehicles.Column(8) will automatically set both OptionButtons to the Correct State.

    --------------------------
    However if your group contains 3 or more OptionButtons you would need a different strategy. You would have to save something that would IDENTIFY the OptionButton that is True. You would need two different routines, one to put the data into the UserForm from the Spreadsheet, and vice versa.

    For example:
    Please Login or Register  to view this content.
    Lewis

+ 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. Hide option buttons based on other option button
    By monfos in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-21-2016, 05:16 PM
  2. enable certain combo buttons based on user selected option buttons
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-20-2013, 06:43 AM
  3. [SOLVED] Multiple option buttons - Need VBA to disable second group of option buttns based on respo
    By ex123 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-19-2013, 03:30 AM
  4. How can I insert multiple sets of option buttons (radio buttons) in Excel 2010?
    By mickwooduclan in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-25-2013, 10:01 AM
  5. [SOLVED] Disabling an Entire Frame with Option Buttons if other Option Buttons are not clicked.
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-20-2012, 04:07 AM
  6. Evaluation with Radio buttons and Option buttons
    By soph0101 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 11-15-2010, 12:23 PM
  7. [SOLVED] Option Buttons-putting questionaire using options buttons
    By Ashman in forum Excel General
    Replies: 2
    Last Post: 07-10-2005, 04:05 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