【发布时间】:2018-03-20 23:40:20
【问题描述】:
我正在尝试编写一个函数来搜索作为参数输入的特定日期,该日期在相邻工作表的一系列单元格中。在查找日期时,该函数应返回一个字符串“found:”和单元格引用。
一切似乎都运行良好,但即使在单元格区域和调用函数时引用的单元格中存在(故意输入的)日期格式的日期时,该函数也会返回“无”。
在使用 Date 时调用 find 时是否遗漏了一些关键信息?
请注意,该函数在另一张表中与调用它的同一行中查找。这可能有助于解释我如何设置 rng
Public Function d_scan(targ As Date) As String
Dim ws As Worksheet
Dim targetSheet As Worksheet
Dim ret As String
Dim rng As String
Dim scanner As Date
Dim found As Range
Set targetSheet = ThisWorkbook.Worksheets("2018")
Set ws = Application.Caller.Worksheet
Let intRow = Application.Caller.Row
Let intCol = Application.Caller.Column
Let rng = "F" & intRow & ":" & "X" & intRow
Set found = targetSheet.Range(rng).Find(What:=targ, LookAt:=xlWhole)
If found Is Nothing Then
Let ret = "nothing"
Else
Let ret = "found: " & found
End If
d_scan = ret
End Function
【问题讨论】: