两个函数功能比较

  • 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

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐