+ Reply to Thread
Results 1 to 4 of 4

Check box or radio buttons

Hybrid View

  1. #1
    Registered User
    Join Date
    04-27-2017
    Location
    New York
    MS-Off Ver
    MS 365 v2211
    Posts
    87

    Check box or radio buttons

    Hello,

    I created a spreadsheet with the easy-to-use check box function. I see that what this really represents is a TRUE/FALSE value in each cell, which makes sense. Is there any way, with check boxes, to allow only one answer to a question? I know that's technically what a radio button is supposed to do, but the check box feature is much neater.

    In the attached example, four businesses are listed and the end-user can select if the business is a client in our region, a client outside of our region, or not a client at all. The ideal would be if only one check box per client can be selected.

    Thanks for pointing me in the right direction!
    Attached Files Attached Files

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,903

    Re: Check box or radio buttons

    One way would be using VBA.

    The below code in the worksheet module would do the trick.
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Cells.Count = 1 Then
            If Not Intersect(Target, Range("B:D")) Is Nothing And Target.Row > 2 Then
                Application.EnableEvents = False
                Select Case Target.Column
                    Case 2
                        If Target = True Then
                            Cells(Target.Row, 3).Resize(1, 2) = False
                        End If
                    Case 3:
                        If Target = True Then
                            Target.Offset(, -1) = False
                            Target.Offset(, 1) = False
                        End If
                    Case 4:
                        If Target = True Then
                            Cells(Target.Row, 2).Resize(1, 2) = False
                        End If
                End Select
                Application.EnableEvents = True
            End If
        End If
    End Sub
    Note: This approach won't work if you're using Excel on a tablet or phone / web version of Excel.

    BSB
    Attached Files Attached Files

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

    Re: Check box or radio buttons

    The radio button is the textbook way to do what you want to do. But you can use checkboxes with data validation to prevent multiple checks in the same row.

    I have added this data validation rule to your file:

    Formula: copy to clipboard
    =COUNTIF($B3:$D3,TRUE)<=1


    The main difference between this and radio buttons is that if you decide you want to change your selection, you have to first uncheck the box you checked, then check the correct on. With radio buttons, only one click needed.

    BTW I don't think this approach will work with controls, only with the new Insert > Checkbox feature.

    EDIT: The post above mine provides VBA that will cause the checkboxes to work just like radio buttons.
    Attached Files Attached Files
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Registered User
    Join Date
    04-27-2017
    Location
    New York
    MS-Off Ver
    MS 365 v2211
    Posts
    87

    Re: Check box or radio buttons

    Thank you both for your quick responses. I haven't learned VBA yet, but it comes up often enough around the forums that perhaps I should take a peek when I have the chance.

    I went with 6StringJazzer's solution (solved) based on my skill level, but it for future readers of this thread, maybe BSB's solution would be the right fit.

+ 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. formatting check boxes and radio buttons
    By ronpalmgren in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-04-2021, 07:42 PM
  2. [SOLVED] Using Radio buttons and Check box on a user form
    By deek in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-18-2020, 12:48 PM
  3. Radio Buttons/Check Boxes and Excel
    By Deepsplinter in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-07-2014, 11:10 AM
  4. How to insert and user of Buttons, Radio buttons, check boxes in excel sheet.
    By krishco in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-03-2013, 02:52 AM
  5. How to insert Buttons, radio buttons and check boxes in Excel
    By krishco in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-01-2013, 08:13 AM
  6. Check buttons ( or radio)
    By philmetz in forum Excel General
    Replies: 3
    Last Post: 08-21-2009, 11:19 AM
  7. Check Boxes / Radio Buttons
    By tekman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-26-2007, 12:52 PM

Tags for this Thread

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