excel vba - 检查单选按钮是否被选中?

发布于 2024-12-07 08:36:46 字数 440 浏览 0 评论 0原文

bt

我正在尝试检查这些简单单选按钮组的值,但我的语法已关闭,有谁知道该怎么做改变? 注意:它们是 Excel 选项按钮而不是 ActiveX 按钮,并且不在用户窗体上。

 If Worksheets("Input").Shapes("Option Button 3").Select.Value = xlOn Then
     MsgBox "fir"
 ElseIf Worksheets("Input").Shapes("Option Button 4").Select.Value = xlOn Then
     MsgBox "sec"
 Else
     MsgBox "none" 'in case they were deleted off the sheet
 End If

bt

I'm trying to check the value of these simple radio button groups but my syntax is off, does anyone know what to change?
Note: they are Excel Option Buttons not ActiveX ones and they are not on a userform.

 If Worksheets("Input").Shapes("Option Button 3").Select.Value = xlOn Then
     MsgBox "fir"
 ElseIf Worksheets("Input").Shapes("Option Button 4").Select.Value = xlOn Then
     MsgBox "sec"
 Else
     MsgBox "none" 'in case they were deleted off the sheet
 End If

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅浅淡淡 2024-12-14 08:36:46

试试这个

Sub ZX()
    Dim shp3 As Shape
    Dim shp4 As Shape

    On Error Resume Next
    Set shp3 = Worksheets("Input").Shapes("Option Button 3")
    Set shp4 = Worksheets("Input").Shapes("Option Button 4")
    On Error Goto 0 
    If shp3 Is Nothing Then
        If shp4 Is Nothing Then
            MsgBox "none" 'in case they were deleted off the sheet
        ElseIf shp4.ControlFormat.Value = xlOn Then
            MsgBox "sec"
        Else
            MsgBox "Only Button 4 exists and it is off"
        End If
    Else
        If shp3.ControlFormat.Value = xlOn Then
            MsgBox "fir"
        Else
            If shp4 Is Nothing Then
                MsgBox "Only Button 3 exists and it is off"
            ElseIf shp4.ControlFormat.Value = xlOn Then
                MsgBox "sec"
            Else
                MsgBox "Both exists, both are off"
            End If
        End If
    End If

End Sub

Try this

Sub ZX()
    Dim shp3 As Shape
    Dim shp4 As Shape

    On Error Resume Next
    Set shp3 = Worksheets("Input").Shapes("Option Button 3")
    Set shp4 = Worksheets("Input").Shapes("Option Button 4")
    On Error Goto 0 
    If shp3 Is Nothing Then
        If shp4 Is Nothing Then
            MsgBox "none" 'in case they were deleted off the sheet
        ElseIf shp4.ControlFormat.Value = xlOn Then
            MsgBox "sec"
        Else
            MsgBox "Only Button 4 exists and it is off"
        End If
    Else
        If shp3.ControlFormat.Value = xlOn Then
            MsgBox "fir"
        Else
            If shp4 Is Nothing Then
                MsgBox "Only Button 3 exists and it is off"
            ElseIf shp4.ControlFormat.Value = xlOn Then
                MsgBox "sec"
            Else
                MsgBox "Both exists, both are off"
            End If
        End If
    End If

End Sub
缘字诀 2024-12-14 08:36:46

我有类似的问题。为了解决这个问题,我决定使用带有此宏 VBA 代码的切换按钮来访问其值并相应地切换我的显示:

Call ThisWorkbook.Sheets("MySheet").toggleDisplay(CBool(ThisWorkbook.Sheets("MySheet").ToggleButton1.Value))

I had a similar problem. To solve it, I decided to use a toggle button with this macro VBA code to access its value and toggle my display accordingly to it:

Call ThisWorkbook.Sheets("MySheet").toggleDisplay(CBool(ThisWorkbook.Sheets("MySheet").ToggleButton1.Value))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文