I am trying to make a function that has 3 inputs, were two of them are optional: colOffsetA
& colOffsetB
. If only one of the two optional ones is used in the function, then I wish that this value is automatically assigned to the empty one as well. Right now the code assigns the value 0 for colOffsetB
for some reason.
Function TestCode(cellA As Range, Optional colOffsetA As Variant, Optional colOffsetB As Variant) As String
If IsEmpty(colOffsetB) Then
colOffsetB = colOffsetA
End If
I believe what your looking for is IsMissing
instead of IsEmpty
. Try this:
If IsMissing(colOffsetB) = True Then
colOffsetB = colOffsetA
End If
Here is a great article on Optional arguments.
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