是否可以在Excel VBA用户定义函数中包含多个if语句

时间:2017-09-27 19:36:42

标签: excel-vba if-statement user-defined-functions vba excel

我在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

当我在电子表格中使用该功能时,只有第二个if语句有效,第一个语句会产生#value。我相信我的sytax是正确的,所以我不确定我哪里出错了。

由于

1 个答案:

答案 0 :(得分:1)

这对你有帮助吗?

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