title: VBA - Matching time in 2 different excel
body: <p>I would like to match workbook1 (A2) time to workbook2 (C4:C27) and return the value of row.</p>
  
  <p>Workbook1
  2:00 AM</p>
  
  <p>Workbook2</p>
  
  <p>12:00 AM
  1:00 AM
  2:00 AM
  3:00 AM
  4:00 AM
  5:00 AM
  6:00 AM
  7:00 AM
  8:00 AM
  9:00 AM
  10:00 AM
  11:00 AM
  12:00 PM
  1:00 PM
  2:00 PM
  3:00 PM
  4:00 PM
  5:00 PM
  6:00 PM
  7:00 PM
  8:00 PM
  9:00 PM
  10:00 PM
  11:00 PM</p>
  
  <p>Below is my code</p>
  
  <pre><code>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 &amp; "pre*.xls")
  Set wbkSource = Workbooks.Open(mypath &amp; fn)
  ctm = Format(tm, "h:mm AM/PM")
  
  intValueToFind = ctm
  'MsgBox ("time is " &amp; ctm)
  
      For i = 4 To 27
          If Cells(i, 3).Value = intValueToFind Then
              MsgBox ("Found value on row " &amp; 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
  </code></pre>
  
  <p>But it always return value not found. kindly help.</p>