使用Excel VBA,我正在尝试检查日期是否为银行假期(或不是)。但是,除非该日期是银行假日数组中第1个银行假日,否则我会一直得到#N / A。(或者在以下情况下,显示“未找到”消息),唯一匹配的时间是日期是“银行假期”数组中列出的第一个。我查看了所有已记录的“ Vlookup-#N / A查询,但看不到我的特定问题的答案。我可以使用x = 1到9的For-Next循环来遍历Bank_Holiday,它运行良好,为什么Vlookup无法正常工作?
Dim Bank_Holiday(1 To 9) As Long
Dim thisdate As Long
Dim found As Boolean
Dim nextdate As String
Dim y As Variant
'将“银行假期”日期(2020年)填充为数字
Bank_Holiday(1) = 43833
Bank_Holiday(2) = 43931
Bank_Holiday(3) = 43934
Bank_Holiday(4) = 43955
Bank_Holiday(5) = 43976
Bank_Holiday(6) = 44074
Bank_Holiday(7) = 44190
Bank_Holiday(8) = 44193
Bank_Holiday(9) = 44197
Windows("bankacct20 - Copy.xlsx").Activate ' An available workbook
Sheets("Jan_Mar20").Select 'An available worksheet
ActiveSheet.Cells(5, 1).Select 'Top of the "Date" column
thisdate = ActiveCell() 'pick up the date
y = Application.VLookup(thisdate, Bank_Holiday, 1, False)
If Not (IsError(y)) Then
found = True
End If
nextdate = Format(thisdate, "dddd dd mm yyyy")
If found Then
MsgBox ("Congratulations! " & nextdate & " Found!")
Else
MsgBox ("The Bank Holiday date " & nextdate & " does not exist")
End If
我希望当活动单元是银行假期时,该消息框会反映出来。