Mutuelinvestor
Mutuelinvestor

Reputation: 3538

Is it possible to have more than one if statement in an excel VBA User Defined Function

I've created the following function in Excel VBA:

Function GetBTM(bai As Integer, comment As String, amt As Double)
If (bai = 195) Then
  GetBTM = "Customer Wires"
End If

If (bai = 399 And Application.WorksheetFunction.Find("MOV TIT", comment) > 0) Then
  GetBTM = "Customer Wires"
End If

End Function

When I use the function in a spreadsheet, Only the second if statment works, the first statement results in #value. I believe my sytax is correct, so I'm not sure where I am going wrong.

Thanks

Upvotes: 0

Views: 66

Answers (1)

K.Dᴀᴠɪs
K.Dᴀᴠɪs

Reputation: 10139

Does this help you?

Public Function GetBTM(bai As Integer, comment As String, amt As Double)

    If (bai = 195) Then
      GetBTM = "Customer Wires"
    ElseIf (bai = 399 And Application.WorksheetFunction.Find("MOV TIT", comment) > 0) Then
      GetBTM = "Customer Wires"
    End If

End Function

Upvotes: 1

Related Questions