David912
David912

Reputation: 396

Optional parameter in custom function

The following custom function takes one optional integer as argument. If the argument is missing, should return 1. If the argument was passed, should return the argument value.

The problem: if the argument is missing, the function returns 0 instead of 1.

any thoughts?

Function f(Optional i As Integer) As Integer
If IsMissing(i) Then
f = 1
Else
f = i
End If
End Function

Upvotes: 1

Views: 954

Answers (1)

shahkalpesh
shahkalpesh

Reputation: 33476

Function f(Optional i As Integer = 1) As Integer
   f = i
End Function

Upvotes: 4

Related Questions