在CheckBoxes上循环以求和与CheckBoxes相对应的值

时间:2018-09-27 11:28:32

标签: excel loops checkbox

在此基础上,我尝试循环执行复选框以获取与这些复选框对应的数据总和:

exemple

我的问题是我有200个复选框,所以我真的不能依靠单个事件。我一直在寻找解决方案,并且听说过OLEObject。

这是我的尝试,请让我知道问题出在哪里以及如何正确编写它,以便为复选框创建足够的循环(描述相应的行):

 Sub Sommer()

Dim i As Byte
For i = 7 To 15 
If ThisWorkbook.Worksheets(2).OLEObject("CheckBox" & i).Value = True And ThisWorkbook.Worksheets(2).Cells(i, 4) = "" Then

For Each j In Array(7, 8, 9, 10, 13, 14, 15)
ThisWorkbook.Worksheets(2).Cells(6, j).Value = ThisWorkbook.Worksheets(2).Cells(6, j).Value + ThisWorkbook.Worksheets(2).Cells(i, j).Value
ThisWorkbook.Worksheets(2).Cells(i, 4).Value = "Sélectionné"
Next j

ElseIf ThisWorkbook.Worksheets(2).OLEObject("CheckBox" & i).Object.Value = False And ThisWorkbook.Worksheets(2).Cells(i, 4) = "Sélectionné" Then

For Each j In Array(7, 8, 9, 10, 13, 14, 15)
ThisWorkbook.Worksheets(2).Cells(6, j).Value = ThisWorkbook.Worksheets(2).Cells(6, j).Value - ThisWorkbook.Worksheets(2).Cells(i, j).Value
ThisWorkbook.Worksheets(2).Cells(i, 4).Value = ""
Next j

End If
Next i

End Sub

0 个答案:

没有答案