以下代码抛出 Object Required (Error 424)
在 if 语句比较 Nothing
独立于给定的值。为什么?
Public Function SqlizeCellValue(ByVal Value As Variant) As Variant
If Value Is Nothing Then
SqlizeCellValue = Nothing
ElseIf Value = Null Then
SqlizeCellValue = Null
ElseIf Value = "" Then
SqlizeCellValue = Null
ElseIf Value = "0" Then
SqlizeCellValue = Null
ElseIf Value = "---" Then
SqlizeCellValue = Null
ElseIf LCase(Value) = "n.c." Then
SqlizeCellValue = Null
Else
SqlizeCellValue = Value
End If
End Function
Public Sub TestSqlizeCellValue()
Debug.Assert SqlizeCellValue("") Is Null
Debug.Assert SqlizeCellValue("0") Is Null
Debug.Assert SqlizeCellValue("---") Is Null
Debug.Assert SqlizeCellValue(Nothing) Is Nothing
Debug.Assert SqlizeCellValue(Null) Is Null
End Sub
最佳答案
因为 Value
在您的函数定义中设置为类型 Variant
只有一个 Object
可以 Set
至 Nothing
关于vba - 为什么 "If Value is Nothing"抛出 "Object Required (Error 424)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38228269/