+ Reply to Thread
Results 1 to 5 of 5

Radio Buttons in cells without control toolbox

Hybrid View

  1. #1
    Registered User
    Join Date
    09-12-2009
    Location
    Las Vegas, Nevada
    MS-Off Ver
    Excel 2003
    Posts
    7

    Radio Buttons in cells without control toolbox

    Instead of using radio buttons from the control toolbox, I have created a radio button type of group within 3 cells the code is as follows:
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then [C1,E1].ClearContents
    If Target.Address = "$C$1" Then [A1,E1].ClearContents
    If Target.Address = "$E$1" Then [A1,C1].ClearContents
    End Sub 
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
        If Target.Cells.Count > 1 Then Exit Sub
    
            If Not Intersect(Target, Range("A1, C1, E1 ")) Is Nothing Then
    
                Target.Font.Name = "Webdings"
    
                    If Target = vbNullString Then
    
                        Target = "g"
    
                    Else
    
                        Target = vbNullString
    
                    End If
    ‘End Code
    
    What this does is puts an “g” in the cell that is clicked on and clears the other two cells. What I want it to do instead is to put a “c” in the cells that are cleared. With the Webdings font this makes the cells with a "g" in them look like a filled checked box and the cells with a "c" in them an unfilled checked box. 
    
    I have tried the following code and it works with an exception. The cell that you want to select has to be selected twice (clicked in once, clicked out of once, then click in again).
    
    ‘Begin Code
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$A$1" Then [C1,E1] = "c"
    If Target.Address = "$C$1" Then [A1,E1] = "c"
    If Target.Address = "$E$1" Then [A1,C1] = "c"
    End Sub 
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
        If Target.Cells.Count > 1 Then Exit Sub
    
            If Not Intersect(Target, Range("A1, C1, E1 ")) Is Nothing Then
    
                Target.Font.Name = "Webdings"
    
                    If Target = vbNullString Then
    
                        Target = "g"
    
                    Else
    
                        Target = vbNullString
    
                    End If
    Any help is greatly appreciated.
    Last edited by Leith Ross; 09-13-2009 at 02:56 PM. Reason: Added Code Tags

  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,259

    Re: Radio Buttons in cells without control toolbox

    Hello tracktor,

    Welocme to the Forum!

    To make your posts easier to read, copy, and edit please wrap your code. I did it for you this time. Here is how you can do it next time.

    How to wrap your Code
    1. Select all your code using the mouse.
    2. Click on the # icon on the toolbar in the Message window. This will automatically wrap the text you selected with the proper Code tags to create a Code Window in your post.

    OR you can also do this Manually by placing the tags
    [code] at the start of the first line,
    [/code] at the end of the last line.

    As a member, You have agreed to follow the forum posting rules. Please take so time to familiarize yourself with the Do's and Don'ts here in the Forum, just click on the link below...

    Forum Rules
    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 Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Radio Buttons in cells without control toolbox

    If I understand your question, try this:
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        With Target
            If .Count > 1 Then Exit Sub
            With Range("A1,C1,E1")
                If Intersect(Target.Cells, .Cells) Is Nothing Then Exit Sub
                .Value = "c"
                .Font.Name = "Webdings"
            End With
            .Value = "g"
        End With
    End Sub
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    09-12-2009
    Location
    Las Vegas, Nevada
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Radio Buttons in cells without control toolbox

    That worked perfectly! Thank you very much!

  5. #5
    Registered User
    Join Date
    09-12-2009
    Location
    Las Vegas, Nevada
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Radio Buttons in cells without control toolbox

    That worked perfectly but I have several rows with these checkboxes all throughout my worksheet, and they are in groups of 2,3,4,5 and 6 cells. ie. A1, C1, E1, then one on A9, C9, E9, G9, then one on A14,C14 and so on. How do I code that?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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