EXCEL VBA:如何使用 isString 或 isNumeric 验证值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26427706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 04:53:56 来源:igfitidea点击:
EXCEL VBA : How to validate value with isString or isNumeric?
提问by Anon231125
Here is my code below:
这是我的代码如下:
Dim m As String, n As Long
n = InputBox("Enter sales amount: ")
If n < 500 Or n > 5000 Then
ActiveCell.Value = n
ActiveCell.Interior.Color = RGB(255, 0, 0)
m = InputBox("Reason why increase/decrease? ")
ActiveCell.Offset(0, 1).Value = m
ActiveCell.Offset(1, 0).Select
Else
ActiveCell.Value = n
ActiveCell.Offset(1, 0).Select
End If
I was figuring out how do I validate value if input was string then inputbox will prompt and ask for integer ? Thanks in advance for the answers.
我想知道如果输入是字符串,我如何验证值然后输入框会提示并要求输入整数?预先感谢您的回答。
回答by Mr. Mascaro
Code:
代码:
Dim m As String, n As String, sales as long
TryAgain:
n = InputBox("Enter sales amount: ")
If Not IsNumeric(n) Then
MsgBox "Entry should be a number!"
GoTo TryAgain
End If
sales = CLng(n)
If sales < 500 Or sales > 5000 Then
ActiveCell.Value = sales
ActiveCell.Interior.Color = RGB(255, 0, 0)
m = InputBox("Reason why increase/decrease? ")
ActiveCell.Offset(0, 1).Value = m
ActiveCell.Offset(1, 0).Select
Else
ActiveCell.Value = sales
ActiveCell.Offset(1, 0).Select
End If