View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Daniel.M Daniel.M is offline
external usenet poster
 
Posts: 32
Default Application.Match with Times

Hello,

Why not round the value AND the searched ranged?

Sub TimesAgain()
Dim C As Range
Dim rng As Variant
Dim TimeToFind As Double
Dim res As Variant

rng = Evaluate("=Transpose(ROUND(times,6))") ' Done once

For Each C In Range("A10:F10") ' ajust for the searched values
TimeToFind = Round(C, 6)
res = Application.Match(TimeToFind, rng, 0)
' here do something more meaningful
Debug.Print C.Address, IIf(IsError(res), "Not matched", res)
Next C

End Sub

Regards,

Daniel M.

"Patrick Molloy" wrote in message
...
The issue is most likely because time is saved internally
as decimal part of a day. so 14:30 is 14.5 hoyrs or
14.5/24 = 0.6041666 recurring

You might consider entering th etime in the lookup column
as text ? ie '14:30
not ideal I'm afraid.

Patrick Molloy
Microsoft Excel MVP

-----Original Message-----
I've been at this problem for a while now, and could not
find any guidance in previous posts.

I have a range 6 X 10 of times that coorespond to a
schedule.
Start Break MealStart MealStop Break End
10:30 AM 12:00 PM 2:30 PM 3:30 PM 5:00 PM
7:00 PM

I then have a single row of times from midnight to 11:45
PM, in incriments
of 15 minutes.
12:00 AM 12:15 AM 12:30 AM 12:45 AM 1:00
AM etc

I am writing a macro that will iterate cell by cell
through the schedule
times and return the cooresponding column number

matching
the time in the
single row (range named as "times").

Dim rng as Range
Dim TimeToFind as Double
Dim res as Variant
Dim CurRow, CurCol as Integer

CurCol = 1
CurRow = 1
Set rng = Range("times")
TimeToFind = CDbl(Cells(CurRow, CurCol))
res = Application.Match(TimeToFind, rng, 0)

Certain times are not being found, despite that they are
clearly there! It
has no trouble finding 10:30 AM (serial: 0.4375), or

12:00
PM (serial: 0.5).
It pukes on 2:30 PM.

Can anyone shed some light on this or point me in the
right direction?
Thanks for your assistance!


.