【发布时间】:2016-05-23 20:50:00
【问题描述】:
这是给出问题的函数:
它应该检查一个字符串是否只有数字 0-9
Public Function onlyNumbers(str As String)
For i = 1 To Len(str)
If Not (IsNumber(Mid(str, i, 1))) Then
onlyNumbers = False
End If
Next
onlyNumbers = True
End Function
模块:
Dim value as string
For j = 2 to 2205
value = Cells(j, 2)
value = Trim(Replace(Replace(value, "-", ""), ".", ""))
'Error gives on the if check (it highlights "value") :
If onlyNumbers(value) Then
' code goes on... no syntax error, execution only
【问题讨论】:
-
在之前添加
call或删除()。 -
IsNumber 不是 vba。试试 IsNumeric()
-
您的 UDF 也将始终返回 true。发现错误需要退出函数。
-
@ScottCraner 至少在 excel 2007 中,这就是你返回的方式,设置返回会导致语法错误
-
问题是你使用
value一个已经在vba中使用过的词,将变量更改为一些非vba词,如vlu或其他东西。