Percentage of checkboxes ticked

suttieb

New Member
Joined
Jun 17, 2005
Messages
33
Hi,
I have a userform with 14 checkboxes.
Is there any way I can keep a running total and percentage of how many boxes have been ticked?
For info they are not all in the same frame if that makes any difference?

Ta

Sut
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi Sut,

Maybe something like this:
Code:
Private Sub CommandButton1_Click()

Dim iTot As Integer, iCount As Integer
Dim CTL As Control
Dim sText As String
For Each CTL In Me.Controls
    If TypeName(CTL) = "CheckBox" Then
        iTot = iTot + 1
        If CTL.Value = True Then iCount = iCount + 1
    End If
Next CTL
MsgBox iCount & " of " & iTot & " checked"
End Sub
 
Upvote 0
Took Far to long... :(

Code:
Private Sub CommandButton1_Click()

Dim objCheckBx As Control
Dim iCountCB As Long
Dim iCountEnabledCB As Long
Dim iCBPercent As Double
    
    For Each objCheckBx In Me.Controls
        If TypeOf objCheckBx Is MSForms.CheckBox Then
            iCountCB = iCountCB + 1
            If objCheckBx = True Then iCountEnabledCB = iCountEnabledCB + 1
        End If
    Next

iCBPercent = Application.WorksheetFunction.Sum(iCountEnabledCB) / iCountCB

MsgBox Format(iCBPercent, "0%") & " of the Check Boxes Have Been Checked"

End Sub
 
Upvote 0
Fab...
However, I have 5 pages in a multipage, each one having between 10 and 14 boxes on each. the above calc looks at all the boxes on the userform.. Can I restrict it to each page in the multipage?
 
Upvote 0
Try This:

Code:
Private Sub CommandButton1_Click()

Dim objCheckBx As Control
Dim iCountCB As Long
Dim iCountEnabledCB As Long
Dim iCBPercent As Double
Dim i As Integer
Dim strPageName As String
    
For i = 0 To MultiPage1.Pages.Count - 1
    strPageName = MultiPage1.Pages(i).Name
    For Each objCheckBx In MultiPage1.Pages(i).Controls
        If TypeOf objCheckBx Is MSForms.CheckBox Then
            iCountCB = iCountCB + 1
            If objCheckBx = True Then iCountEnabledCB = iCountEnabledCB + 1
        End If
    Next

iCBPercent = Application.WorksheetFunction.Sum(iCountEnabledCB) / iCountCB

MsgBox Format(iCBPercent, "0%") & " of the Check Boxes on Page " & strPageName & " Have Been Checked"

Next
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,544
Messages
6,120,126
Members
448,947
Latest member
test111

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top