gpt4 book ai didi

excel - 双消息显示-VBA

转载 作者:行者123 更新时间:2023-12-04 21:20:19 25 4
gpt4 key购买 nike

在以下代码中,输入错误的值时会显示错误消息。由于字段为空,删除错误值时再次显示错误消息。如何再次停止显示消息?

Private Sub textbox1_Change()
If TextBox1 < 1 Or TextBox1 > 31 Then
Beep
MsgBox "Please enter numbers between 1 and 31."
TextBox1= ""
TextBox1.SetFocus
End If
End Sub

最佳答案

Private Sub textbox1_Change()
Select Case True
Case Len(TextBox1.Text) = 0

Case TextBox1.Value < 1 Or TextBox1.Value > 31
Beep
MsgBox "Please enter numbers between 1 and 31."
TextBox1 = ""
TextBox1.SetFocus

End Select
End Sub

或者
Private Sub textbox1_Change()
If Len(TextBox1.Text) = 0 Then Exit Sub

If TextBox1 < 1 Or TextBox1 > 31 Then
Beep
MsgBox "Please enter numbers between 1 and 31."
TextBox1 = ""
TextBox1.SetFocus
End If
End Sub

关于excel - 双消息显示-VBA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52903776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com