对于下面的问题,我错误地要求在C.R.进行审查,但是他们告诉我不是正确的地方,所以我向你提出同样的问题。
我无法单独找到答案。这个非常简单的代码返回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,但如果我在即时窗口看到字符串
If d = Sheets("Diary").Range("A12") Then Debug.Print "Yes" Else Debug.Print "no"
检索“是”
有人可以告诉我什么附加?谢谢Fabrizio
答案 0 :(得分:1)
Lookup_value可以是数字,文本或逻辑值。不是约会。因此,将日期值转换为数字。
Var = Application.WorksheetFunction.Match(CDbl(d), Worksheets("Diary").Columns(1), 0)