標題:
[發問] 請問如何計算不同內容的Checkbox?
[打印本頁]
作者:
jemery127
時間:
2015-3-22 22:45
標題:
[發問] 請問如何計算不同內容的Checkbox?
請問大家有關Checkbox的問題,
我希望能夠如下圖,分別計算出"非常滿意"、"滿意"、"不滿意"、"待改進"分別被勾選了幾個?
目前只能寫出所有被勾選的Checkbox個數,卻無法依照各分類去計算,程式碼及檔案都附上,望各位前輩指教,謝謝!
[attach]20480[/attach]
Sub Test()
Dim Ct As OLEObject, iI%
iI = 0
For Each Ct In Me.OLEObjects
If Ct.progID = "Forms.CheckBox.1" Then
If Ct.Object.Value = True Then iI = iI + 1
End If
Next
[B11] = iI
End Sub
複製代碼
[attach]20481[/attach]
作者:
GBKEE
時間:
2015-3-23 06:55
回復
1#
jemery127
試試看
Option Explicit
Sub Test()
Dim Ct As OLEObject, M As Variant, Rng As Range
Set Rng = [a10:A14] '調查表範圍
Rng.Offset(, 1) = ""
For Each Ct In Me.OLEObjects
If Ct.progID = "Forms.CheckBox.1" Then
M = Application.Match(Ct.Object.Caption, Rng, 0)
'工作表函數搜尋完全相同的字串的位置
If Ct.Object.Value = True And IsNumeric(M) Then
Rng(1, 2) = Rng(1, 2) + 1
Rng(M, 2) = Rng(M, 2) + 1
End If
End If
Next
End Sub
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)