Before I code my own function, is there a built-in function in VBA which allows me to specify a default value if a variable / function return value is null? I know of writing out an if conditional statement, but that's a little lengthy. In other languages I could do either a ternary conditional statement, or (I think in Excel) use a function to specify a default value.
e.g.
Dim v as integer
v = DefaultValue(SomeFunction(), 5) ' put 5 in v if SomeFunction returns null
This is my own function that I wrote:
Public Function DefaultValueIfNull(unknown As Variant, optional defaultValue As Variant) As Variant
If IsNull(unknown) Then
DefaultValueIfNull = defaultValue
Else
DefaultValueIfNull = unknown
End If
End Function
Which appears to do exactly the same thing as the inbuilt function Nz(value, valueIfNull) in Access
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With