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.
Edit: or it could exclude the 2 checkboxes I don't want to count by name (cbxSignOff and cbxFullScreen)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
Thanks!
Last edited by ker9; 01-26-2012 at 04:45 PM.
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks