excel vba - 检查单选按钮是否被选中? [英] excel vba - check if radio button is selected?
本文介绍了excel vba - 检查单选按钮是否被选中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图检查这些简单的单选按钮组的值,但是我的语法是关闭的,有没有人知道要改变什么?
注意:它们是不是ActiveX的Excel选项按钮,它们不在用户窗体上。
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
推荐答案
尝试这个
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")
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
这篇关于excel vba - 检查单选按钮是否被选中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文