EXCEL VBA:如何使用isString或isNumeric验证值? [英] EXCEL VBA : How to validate value with isString or isNumeric?
本文介绍了EXCEL VBA:如何使用isString或isNumeric验证值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的代码:
Dim m As String,n As Long
n = InputBox(Enter sales amount:)
如果n < 500或n> 5000然后
ActiveCell.Value = n
ActiveCell.Interior.Color = RGB(255,0,0)
m = InputBox(增加/减少的原因)
ActiveCell .Offset(0,1).Value = m
ActiveCell.Offset(1,0)。选择
Else
ActiveCell.Value = n
ActiveCell.Offset (1,0)。选择
结束如果
我正在弄清楚我如何验证如果input是string,那么inputbox会提示并询问整数?
提前感谢答案。
解决方案
代码:
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
$ bn =输入框(输入销售金额:)
如果不是IsNumeric(n)然后
MsgBox条目应该是一个数字!
GoTo TryAgain
如果
sales = CLng(n)
如果销售< 500或销售> 5000然后
ActiveCell.Value = sales
ActiveCell.Interior.Color = RGB(255,0,0)
m = InputBox(为什么增加/减少的原因)
ActiveCell .Offset(0,1).Value = m
ActiveCell.Offset(1,0)。选择
Else
ActiveCell.Value = sales
ActiveCell.Offset (1,0)。选择
结束如果
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.
解决方案
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
这篇关于EXCEL VBA:如何使用isString或isNumeric验证值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文