excel中怎么计算选中的复选框的个数

来源:百度知道 编辑:UC知道 时间:2024/05/21 10:33:23
在excel中有多个复选框,计算出被选中的复选框的个数在一单元格中显示出来,怎么实现???
请详细说明,加分!!!

假设两个复选框(checkbox),个数在A1中显示。

拷贝下面代码。
Private Sub CheckBox1_Click()
Call RefreshCount(CheckBox1.Value)
End Sub

Private Sub CheckBox2_Click()
Call RefreshCount(CheckBox2.Value)
End Sub

Private Sub RefreshCount(fg As Boolean)
If Trim(Cells(1, 1).Value) = vbNullString Then
If fg Then
Cells(1, 1).Value = 1
End If
Else
If fg Then
Cells(1, 1).Value = CInt(Cells(1, 1).Value) + 1
Else
Cells(1, 1).Value = CInt(Cells(1, 1).Value) - 1
End If
End If
End Sub

迷糊!