在用户窗体 VBA 中使用带有选项按钮的 IF/Then 语句
有没有一种方法可以对选项按钮进行编码,以根据两者的选择给出一个值?我尝试了多种方法,但似乎一事无成。这是我尝试过的最后一个代码,如果可能的话,这就是我希望它工作的方式。这段代码现在的方式是,我只得到一个值。
Private Sub OptBtn()
Dim n As Long
n = Sheets1.Range("A" & Application.Rows.Count).End(xlUp).Row
Range("A" & Rows.Count).End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.EntireRow.Insert
If Me.OptBtn_AddCard.Value = True & Me.OptBtn_ManagedBy.Value = True Then
Sheets1.Range("I" & n + 1).Value = "ACTIVE"
Else
If Me.OptBtn_AddCard.Value = True & Me.OptBtn_ManagedBy.Value = False Then
Sheets1.Range("I" & n + 1).Value = "AVAILABLE"
Else
If Me.OptBtn_AddCard.Value = False & Me.OptBtn_ManagedBy.Value = True Then
Sheets1.Range("I" & n + 1).Value = "ACTIVE"
End If
End If
End If
End Sub
Is there a way to code the option buttons to give a value based off both being selected? I have tried multiple ways and seems I am getting nowhere. This is the last code I have tried and this is how I would like it to work if possible. The way this code is right now, I am only getting one value.
Private Sub OptBtn()
Dim n As Long
n = Sheets1.Range("A" & Application.Rows.Count).End(xlUp).Row
Range("A" & Rows.Count).End(xlUp).Select
ActiveCell.Offset(1, 0).Select
ActiveCell.EntireRow.Insert
If Me.OptBtn_AddCard.Value = True & Me.OptBtn_ManagedBy.Value = True Then
Sheets1.Range("I" & n + 1).Value = "ACTIVE"
Else
If Me.OptBtn_AddCard.Value = True & Me.OptBtn_ManagedBy.Value = False Then
Sheets1.Range("I" & n + 1).Value = "AVAILABLE"
Else
If Me.OptBtn_AddCard.Value = False & Me.OptBtn_ManagedBy.Value = True Then
Sheets1.Range("I" & n + 1).Value = "ACTIVE"
End If
End If
End If
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
And
而不是&
。代码可以这样缩短:
我个人喜欢
Switch()
变体:Use
And
instead of&
.The code can be shortened like this:
I personally like the
Switch()
variation: