Time VBA-两个不同excel中的匹配时间

Time VBA-两个不同excel中的匹配时间,time,matching,Time,Matching,我希望将workbook1(A2)时间与workbook2(C4:C27)匹配,并返回行的值 工作手册1 凌晨2点 工作手册2 上午12:00 凌晨1点 凌晨2点 凌晨三点 凌晨四点 上午五点 早上6点 上午7:00 上午8:00 上午9点 上午10:00 上午11:00 下午12:00 下午1:00 下午2:00 下午三点 下午四点 下午五点 下午六点 下午7:00 晚上八点 晚上九点 晚上10:00 晚上11:00 下面是我的代码 Sub FindMatchingValue() Dim i

我希望将workbook1(A2)时间与workbook2(C4:C27)匹配,并返回行的值

工作手册1 凌晨2点

工作手册2

上午12:00 凌晨1点 凌晨2点 凌晨三点 凌晨四点 上午五点 早上6点 上午7:00 上午8:00 上午9点 上午10:00 上午11:00 下午12:00 下午1:00 下午2:00 下午三点 下午四点 下午五点 下午六点 下午7:00 晚上八点 晚上九点 晚上10:00 晚上11:00

下面是我的代码

Sub FindMatchingValue()

Dim i As Integer
Dim intValueToFind As String
Dim mypath As String
Dim wbkSource As Workbook
Dim tm As Range
Dim ctm As String


Set tm = ThisWorkbook.Worksheets(1).Range("A2")

mypath = "C:\Users\hlfoong\Desktop\Testing\"
fn = Dir(mypath & "pre*.xls")
Set wbkSource = Workbooks.Open(mypath & fn)
ctm = Format(tm, "h:mm AM/PM")

intValueToFind = ctm
'MsgBox ("time is " & ctm)

    For i = 4 To 27
        If Cells(i, 3).Value = intValueToFind Then
            MsgBox ("Found value on row " & i)
            Exit Sub
        End If
    Next i

    ' This MsgBox will only show if the loop completes with no success
    MsgBox ("Value not found in the range!")

End Sub
但它总是返回未找到的值。请帮忙