在 Excel 中,我有一个利用IF()
and函数的OR()
函数。我希望在 Access VBA 中编写一个等效的函数。我该如何为此编写代码?
=IF(OR($X9=1,$X9=2,$X9=3),Y9-1,Y9)
我打算将此 if 函数用作模块:
Function iyear(month as string, year as string) as string
所以在这种情况下,$X9 是月份,Y9 是年份。
在VBA中你可以做这样的事情
Function iyear(month As Long, year As Long) As Long
If month = 1 Or month = 2 Or month = 3 Then
iyear = year - 1
Else
iyear = year
End If
End Function
Sub Main()
MsgBox "month = 1, year = 2013" & vbNewLine & "iyear returns: " & iyear(1, 2013) & vbNewLine & vbNewLine & _
"month = 4, year = 2013" & vbNewLine & "iyear returns: " & iyear(4, 2013)
End Sub