#1
|
|||
|
|||
how to show total of check boxes checked
I have a row of 18 checkboxes and I would like to display a percentage of checkboxes checked to the right of the row. So if nine boxes were checked the percentage would show 50%.
Thanks in advance. |
#2
|
||||
|
||||
What kind of checkboxes (e.g. userform, formfield, content control, Active-X)?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
I used developer design mode.
But if you have an easier way, I'm open to suggestion as it doesn't really matter. |
#4
|
||||
|
||||
All three kinds are accessed via the Developer tab, so telling me that's what you're using isn't telling me anything about what kind they are...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
I don't know how to find that out.
It was a while ago when I created it. I think it is an active x control. When I click on PROPERTIES, it doesn't tell me what it is. |
#6
|
||||
|
||||
Without knowing for sure what you've used, one could spend a lot of time working on the right solution for the wrong kind of checkbox. Can you attach a document to a post with the checkboxes in question (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
attached as requested
|
#8
|
||||
|
||||
Your checkboxes are indeed of the Active-X type. To get the desired tally you could use a macro like:
Code:
Sub CountChecks() Dim iShp As InlineShape, i As Long, j As Long, StrPct As String For Each iShp In ActiveDocument.InlineShapes If Not iShp.OLEFormat Is Nothing Then If iShp.OLEFormat.ClassType = "Forms.CheckBox.1" Then i = i + 1 If iShp.OLEFormat.Object.Value = True Then j = j + 1 End If End If Next If i <> 0 Then StrPct = " (i.e. " & Format(j / i, "0.0%") & ")" End If MsgBox j & " of " & i & " checkboxes" & StrPct & " are checked." End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Would I have to click a macro button to get the total?
I was actually looking for a solution whereby the total was automatically updated when a box was checked. |
#10
|
||||
|
||||
Yes, you could do that. For example, if you go into Design Mode and double-click on your last checkbox, the VBE will open up with a sub named 'Checkbox117_Click()'. If you edit that so it reads:
Code:
Private Sub Checkbox117_Click() Call CountChecks End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
As you can see, that means that the code runs if THAT checkbox is clicked. If you want
Code:
whereby the total was automatically updated when a box was checked. |
#12
|
||||
|
||||
Or you could add an ActiveX command button to the document and run the macro from that. So many possibilities ...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
I was actually thinking of a commandbutton beside them, and that this is a "manual" execution, as you have to DO something. Personally, I think I would use a simple keyboard shortcut to run the code. And I would put the content (the text of the percentage) into a textbox, or a bookmark.
|
#14
|
|||
|
|||
Quote:
Your method works perfectly but uses a pop-up. My objective was to put a running total / percent to the right of all the check boxes. |
#15
|
||||
|
||||
If you create a textbox for the output to go to, you could change 'MsgBox ' to:
'ActiveDocument.Shapes(1).TextFrame.TextRange.Text = ' It would be better, though, to put your checkboxes into a 2-column, 1-row table, so the output can be sent to the second cell in the table. That's because the above method relies on the textbox being the first logical one in the document, whereas a table reference can be made more specific.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
check box percentage |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Repeat Spell check in a doc that has already been checked | mawigfie | Word | 1 | 08-22-2012 01:16 PM |
Word2010 check boxes and plain text content control boxes in same table | fcsungard | Word | 5 | 06-01-2012 01:16 AM |
Create makro that counts the number of checked tick boxes in a survey | johannapaj | Word VBA | 0 | 09-05-2011 01:51 AM |
I Checked "Don't show again" and now I want it back. | WaltR | Word | 1 | 02-03-2011 03:20 AM |
Problem with Developer Form -- Check Boxes and Text Boxes | PCC | Word | 1 | 05-16-2009 05:22 AM |