Results 1 to 5 of 5

Mutiple Checkboxes using SetCheckBoxes Function to change state of several checkboxes

Threaded View

  1. #1
    Registered User
    Join Date
    10-01-2012
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    7

    Mutiple Checkboxes using SetCheckBoxes Function to change state of several checkboxes

    Hi,

    I have a spreadsheet with 100 to 150 checkboxes on it. I have them separated into 3 to 4 checkboxes going down one column with several empty cells between them. I want each group of 3 to 4 checkboxes to only show one checkbox as true at a time. If a checkbox without a check in it is checked, the other checkbox with the check in it become unchecked. I found the code below SetCheckBoxes, and it works great for one set of checkboxes, say Checkboxes 1-3, but when I try using this same function again to duplicate the function for, say for Checkboxes 4-7, I get a “Compile error: Ambiguous name detected: SetCheckBoxes”. How can I make each group of checkboxes work independently from each other? I am very limited to my knowledge of VBA.

    Thank You,

    drm51

    Here is the code I found:

    Private Sub CheckBox1_Change()
        SetCheckBoxes 1
    End Sub
    
     Private Sub CheckBox2_Change()
        SetCheckBoxes 2
    End Sub
     
    Private Sub CheckBox3_Change()
        SetCheckBoxes 3
    End Sub
     
     Private Function SetCheckBoxes(CBIndex As Long)
        Dim x As Long
         
        If Me.OLEObjects("CheckBox" & CBIndex).Object.Value Then
            For x = 1 To 3
                If x <> CBIndex Then
                    Me.OLEObjects("CheckBox" & x).Object.Value = False
                End If
            Next x
        End If
    End Function
    Last edited by Leith Ross; 04-28-2013 at 01:25 AM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

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

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