我有两种类型的复选框。
每种类型的复选框都在其“列”中定义:
"CheckBoxeMacro"&i
(在第3列中),并且"CheckBox"&i
。只要要添加的数据设置在我的第一种类型的复选框("checkboxMacro"&i
所在的两个单元格之间的行中,我就希望使用第二种类型的复选框来描述有关总和的指令。
我尝试了此操作,但似乎错误地使用了“ TypeOf
”。
当单元格包含复选框而不是数字或Nothing时,我们必须停止这一事实,如何才能停止到正确的行?
Sub SommerTest()
Dim i As Byte
For r = 1 To 178
If TypeOf Sheets(2).Cells(r, 3) Is Object Then
For i = r + 1 To 178
While IsNumeric(Sheets(2).Cells(i, 3)) _
And (Sheets(2).Cells(i, 3).Value <> "")
With Sheets(2)
If .OLEObjects("CheckBox" & i).Object.Value = True _
And ThisWorkbook.Worksheets(2).Cells(i, 4)="" Then
For Each j In Array(7, 8, 9, 10, 15, 16, 17)
ThisWorkbook.Worksheets(2).Cells(r, j).Value = _
ThisWorkbook.Worksheets(2).Cells(r, j).Value _
+(ThisWorkbook.Worksheets(2).Cells(i, j).Value) _
*(ThisWorkbook.Worksheets(2).Cells(i, 3).Value)
ThisWorkbook.Worksheets(2).Cells(i, 4).Value _
= "Sélectionné"
Next j
ElseIf .OLEObjects("CheckBox" & i).Object.Value = False _
And ThisWorkbook.Worksheets(2).Cells(i, 4) _
= "Sélectionné" Then
For Each j In Array(7, 8, 9, 10, 15, 16, 17)
ThisWorkbook.Worksheets(2).Cells(r, j).Value = _
ThisWorkbook.Worksheets(2).Cells(r, j).Value _
-(ThisWorkbook.Worksheets(2).Cells(i, j).Value) _
*(ThisWorkbook.Worksheets(2).Cells(i, 3).Value)
ThisWorkbook.Worksheets(2).Cells(i, 4).Value = ""
Next j
End If
End With
Wend
Next i
End If
Next r
End Sub
答案 0 :(得分:3)
正如@Rory所说,您可以围绕topleftcell
属性进行调查,不确定与控件大小有关的准确性,但是类似
.shapes("CheckBox21").oleformat.object.topleftcell.address
.oleobjects("CheckBox21").topleftcell.address
Dim s as shape
for each s in activesheet.shapes
if s.oleformat.object.topleftcell.address=activecell.address.......
end if
next s
希望这会有所帮助。