count1 = 0
For Each cell In worktotalDXdept1
cell.NumberFormat = "h:mm AM/PM"
If InStr(cell.Text, "x") > 0 Then
n = Len(Trim(cell))
cellval = Left(Trim(cell), n - 5) & ":" & Left(Right((Trim(cell)), 4), 2) & " AM"
If cellval >= fromTime And cellval < toTime Then
count1 = count1 + 1
End If
End If
If Not InStr(cell.Text, "x") > 0 Then
If cell.Text >= fromTime And cell.Text < toTime Then
count1 = count1 + 1
End If
End If
Next
MsgBox "There are " & count1 & " trips from " & fromTime & " to " & toTime & " ."
This code works for one column of times, however when I enter a range of times outside the specified row, count1 always returns "0" trips. How can I have it search multiple columns of time?
Bookmarks