+ Reply to Thread
Results 1 to 2 of 2

Thread: Count True Checkboxes with certain name configuration

  1. #1
    Forum Contributor
    Join Date
    06-16-2010
    Location
    Tampa, FL
    MS-Off Ver
    Excel 2007
    Posts
    184

    Count True Checkboxes with certain name configuration

    Hi, I have the following code that will count all the true checkboxes on my worksheet - it works great. However, what I need to do is only count the boxes that begin with "cb" (cb1, cb2, cb3, etc) or it can start with all checboxes in row 12 and beyond.

    Edit - code is not working, it returns 0 for everything (they are active x boxes not form boxes)

    Any assistance would be much appreciated.

    Sub CheckboxTrue()
    Dim counter As Integer
    counter = 0
    
    Dim chk As CheckBox
        For Each chk In Sheet1.CheckBoxes
            If chk.Value = 1 Then '1 is true
                counter = counter + 1
            End If
         Next chk
    MsgBox ("Count = " & counter)
    End Sub
    Edit: or it could exclude the 2 checkboxes I don't want to count by name (cbxSignOff and cbxFullScreen)
    Thanks!
    Last edited by ker9; 01-26-2012 at 04:45 PM.

  2. #2
    Forum Guru
    Join Date
    06-18-2004
    Location
    Canada
    Posts
    1,329

    Re: Count True Checkboxes with certain name configuration

    Try...

    Option Explicit
    
    Sub test()
    
        Dim OleObj As OLEObject
        Dim Cnt As Long
        
        Cnt = 0
        For Each OleObj In Sheet1.OLEObjects
            If TypeName(OleObj.Object) = "CheckBox" Then
                Select Case OleObj.Name
                    Case "cbxSignOff", "cbxFullScreen"
                        'Do nothing
                    Case Else
                        If OleObj.Object.Value = True Then
                            Cnt = Cnt + 1
                        End If
                End Select
            End If
        Next OleObj
        
        MsgBox "Count = " & Cnt
        
    End Sub
    
    Domenic
    Microsoft MVP - Excel
    xl-central.com, "Your Quick Reference to Excel Solutions"

+ Reply to Thread

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.2.0