如何select在Excel中使用特定的表单控件复选框?
How to select specific form control checkboxes in Excel?
我在 Excel 2010 年工作。
我在我的工作表中设置了 10 个表单控件复选框,我想自动 select 一组特定的复选框。我之前看到的关于此主题的所有 post 涵盖 select 所有复选框或取消 select 所有复选框。
这是来自先前 post 的 VBA 代码,用于取消select所有复选框:
Sub clearcheck()
Dim sh As Worksheet For Each sh In Sheets
On Error Resume Next
sh.CheckBoxes.Value = False
On Error GoTo 0 Next sh
End Sub
这是基于这条链的更新代码,但它仍然运行成为一个语法问题以及一个未识别的子链:
Sub highengagedonline()
Dim cb As CheckBox, sht As Worksheet
Set sht = Worksheets("Graph")
For Each cb In sht.CheckBoxes
If cb.Name = "Check Box 35" or _
cb.Name = "Check Box 36" or _
cb.Name = "Check Box 37" or _
cb.Name = "Check Box 38" or _
cb.Name = "Check Box 39" Then
cb.Value = 1
Else: cb.Value = 0
End If
Next cb
End Sub
尝试以下方法:
Sub ClearCheck()
Dim cb As CheckBox, sht As Worksheet
Set sht = Worksheets("Sheet1")
For Each cb In sht.CheckBoxes
If cb.Name = "Check Box 1" Then
cb.Value = 1
Else if cb.Name = "Check Box 2" Then
cb.Value = 0
End If
Next cb
End Sub
我在 Excel 2010 年工作。
我在我的工作表中设置了 10 个表单控件复选框,我想自动 select 一组特定的复选框。我之前看到的关于此主题的所有 post 涵盖 select 所有复选框或取消 select 所有复选框。
这是来自先前 post 的 VBA 代码,用于取消select所有复选框:
Sub clearcheck()
Dim sh As Worksheet For Each sh In Sheets
On Error Resume Next
sh.CheckBoxes.Value = False
On Error GoTo 0 Next sh
End Sub
这是基于这条链的更新代码,但它仍然运行成为一个语法问题以及一个未识别的子链:
Sub highengagedonline()
Dim cb As CheckBox, sht As Worksheet
Set sht = Worksheets("Graph")
For Each cb In sht.CheckBoxes
If cb.Name = "Check Box 35" or _
cb.Name = "Check Box 36" or _
cb.Name = "Check Box 37" or _
cb.Name = "Check Box 38" or _
cb.Name = "Check Box 39" Then
cb.Value = 1
Else: cb.Value = 0
End If
Next cb
End Sub
尝试以下方法:
Sub ClearCheck()
Dim cb As CheckBox, sht As Worksheet
Set sht = Worksheets("Sheet1")
For Each cb In sht.CheckBoxes
If cb.Name = "Check Box 1" Then
cb.Value = 1
Else if cb.Name = "Check Box 2" Then
cb.Value = 0
End If
Next cb
End Sub