【发布时间】:2016-07-28 23:22:34
【问题描述】:
希望您对可能很简单的问题有一个优雅的解决方案!
由于工作表的设计方式,我使用的是 ActiveX 选项按钮,但在工作表中而不是用户窗体或组框内。该代码作为子选项包含在选项按钮代码表单中。
这段代码对我正在尝试做的事情非常不言自明:
Public Sub SectionD_Click()
If OptionButton1.Value = True Then
ThisWorkbook.Sheets("Boolean").Range("B2").Value = 1
ElseIf OptionButton2.Value = True Then
ThisWorkbook.Sheets("Boolean").Range("B2").Value = 0
End If
If OptionButton3.Value = True Then
ThisWorkbook.Sheets("Boolean").Range("B3").Value = 1
ElseIf OptionButton4.Value = True Then
ThisWorkbook.Sheets("Boolean").Range("B3").Value = 0
End If
If OptionButton5.Value = True Then
ThisWorkbook.Sheets("Boolean").Range("B4").Value = 1
ElseIf OptionButton6.Value = True Then
ThisWorkbook.Sheets("Boolean").Range("B4").Value = 0
End If
End Sub
我想让“OptionButton”后面的数字使用简单的“i = i + 2”类型语句更改值,但似乎一些 VBA 变量/表达式/对象限制不会让我(对不起,我我是个菜鸟,不知道正确的术语应该是什么)。
如果有人能在这里指出我正确的方向,我将不胜感激!我必须浏览 25 个左右的选项按钮对,我非常希望代码只有 5 行简单的代码,而不是 100 行以上的代码来做同样的事情!
【问题讨论】:
标签: vba excel radio-button activex