Hello all,

So I am trying to devise a code that will allow a user to input a range of times via dialog box. Then with this range (a startTime and endTime), the VBA code will search the worksheet and count the number of trips that take place in that time interval. I can't figure out a way to convert the user entry into a h:mm AM/PM format but I feel like I am on the right track.

If anyone could take a look at my attached code/file and steer me in the right direction, that would be awesome! I would also be happy to clarify anything I left out, thank you.

-Chad


Dim count1 as integer
Set pullinspullouts1 = Worksheets("Pull-ins & Pull-outs").Range("B4", Range("B" & Rows.Count).End(xlUp))

'Convert text to time
fromTime.NumberFormat = "h:mm AM/PM"
toTime.NumberFormat = "h:mm AM/PM"
        
End If

For Each cell In pullinspullouts1
    If InStr(cell.Text, "x") > 0 Then
        n = Len(Trim(cell))
        cellval = Left(Trim(cell), n - 5) & ":" & Left(Right((Trim(cell)), 4), 2) & " AM"
        cell.NumberFormat = "h:mm AM/PM"
    End If
    
    
    If cell.Value >= #fromTime# And cell.Value < #toTime# Then
            count1 = count1 + 1
    End If
    
    MsgBox "There are " & count1 & "trips from " & fromTime & "to " & toTime
timequery.xlsm