Shaneman via OfficeKB.com was telling us:
Shaneman via OfficeKB.com nous racontait que :
I have a form were users need to select a cyheckbox that correspondes
to a rating of 1 thru 4 and I need to get the average score of all.
[quoted text clipped - 10 lines]
How can I do this? Can I do this?
Name each series of checkbox using a pattern like:
One1, One2, One3, One4
Two1, Two2, Two3, Two4
etc.
The actual letters do not matter, as long as each name is unique and that it
finishes with the digits 1 to 4.
Then, set each textbox to calculate on exit and to call the macro called
"Calculate" on Exit.
Finally, have a textbox named "Result" and disable its option "Fill-in
enabled".
But really, it would be easier with a userform and option buttons which are
mutually exclusive....
'_______________________________________
Sub Calculate()
ActiveDocument.FormFields("Result").Result = CStr(GetAverage)
End Sub
'_______________________________________
'_______________________________________
Function GetAverage() As Single
Dim myFormField As FormField
Dim myTotal As Single
Dim myCount As Single
For Each myFormField In ActiveDocument.FormFields
If myFormField.Type = wdFieldFormCheckBox Then
If myFormField.CheckBox.Value = True Then
myTotal = myTotal + CSng(Right(myFormField.Name, 1))
End If
myCount = myCount + 1
End If
Next
GetAverage = Format((myTotal / (myCount / 4)), "#0.0")
End Function
'_______________________________________