VBA 判断是否为数字的函数,application.isnumber() 和 isnumeric() 函数的使用比较 和注意点

 

两个函数功能比较

  • application.isnumber()     '只有是 纯数字 才返回true
  • isnumeric()                       '是 纯数字 或者  纯数字的字符串 都返回true

 

注意点

  • inputbox() 函数返回的是string
  • VBA中,只有"a" 才是字符串。而 a 不是字符串是变量
  • 没有返回值的 变量,语句,都返回空值,也就是0, false

 

Sub cs1()

a1 = 3
b1 = "3"
c1 = a3
d1 = a

Debug.Print Application.IsNumber(a1)
Debug.Print Application.IsNumber(b1)
Debug.Print Application.IsNumber(c1)
Debug.Print Application.IsNumber(d1)
Debug.Print


Debug.Print "a1=" & a1
Debug.Print "b1=" & b1
Debug.Print "c1=" & c1
Debug.Print "d1=" & d1
Debug.Print

Debug.Print IsNumeric(a1)
Debug.Print IsNumeric(b1)
Debug.Print IsNumeric(c1)
Debug.Print IsNumeric(d1)
Debug.Print

'看起来字符串必须引号"" 引起来
'或者是有些函数返回的,指定是字符串型

j1 = 3
k1 = "3"
l1 = "a3"
m1 = "a"


Debug.Print IsNumeric(3)
Debug.Print IsNumeric("3")
Debug.Print IsNumeric("a3")
Debug.Print IsNumeric("a")
Debug.Print


Debug.Print IsNumeric(j1)
Debug.Print IsNumeric(k1)
Debug.Print IsNumeric(l1)
Debug.Print IsNumeric(m1)
Debug.Print


End Sub

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值