匹配搜索和直接检查 cell() 的不同结果

Different result from match search and check directly cell()

下面的问题我在C.R里错误的要求复习,但是他们告诉我不是正确的地方,所以我向你提出同样的问题。

我一个人找不到答案。这个非常简单的代码 return 2 个不同的结果,为什么?!?!我会疯掉的...

Function FirstDay(t As String) As Boolean

d = DateSerial(Left(t, 4), Mid(t, 5, 2), Right(t, 2)) - 1
FirstDay = False
Var = Application.Match(d, Worksheets("Diary").Columns(1), 0)
If Not IsError(Var) Then
   FirstDay = True
End If

'this only to check if direct match Val to cell() retrieve the same result
If d = Sheets("Diary").Range("A12") Then Debug.Print "Yes" Else Debug.Print "no"

End Function

我用 FirstDay("20161107") 调用我的函数 sh("Diary").(columns(1)) 我的范围是

(date,01/01/2016,07/02/2016,06/03/2016,03/04/2016,08/05/2016,05/06/2016,03/07/2016,07/08/2016,04/09/2016,02/10/2016,06/11/2016,04/12/2016)

Var 应该是 12 但我检索了 Error2042 然后 FirstDay = false,但是如果我立即看到 windows 字符串

If d = Sheets("Diary").Range("A12") Then Debug.Print "Yes" Else Debug.Print "no"

检索"Yes"

有人可以告诉我追加的是什么吗?感谢 Fabrizio

Lookup_value可以是数字、文本或逻辑值。不是约会。所以将日期值转换为数字。

Var = Application.WorksheetFunction.Match(CDbl(d), Worksheets("Diary").Columns(1), 0)