i wanted to apply a condition (Deleting rows) if a particular cell format is NOT hourly format
I tried the below code but it doesn't work
Sub delete_row()
Dim i As Integer
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LR
If Not Cells(i, 1).Value Like "##:##-##:##" Then
Cells(n, 1).EntireRow.Delete
End If
Next i
End Sub
Add the below code and I hope this suits your requirement
But, in order to run the below code smoothly, I hope your time value are formatted as TIME.
I have just added additional function IsTime which check the cell value and returns either TRUE/FALSE if cell value is timevalue or not. Here you dont have to worry about particular hour format, you only need to be concern about whether is cell is formatted as TIME or not.
I don't believe there is an out of the box way or a singular pattern match to evaluate a time range the way you are entering it.
This should work though and is flexible enough to accomodate some input variation (spaces before or after the dash, single or double digit hour input (without a leading 0)):
I'd do it like this:
Start at the bottom of the column of values and work upwards, checking for cell format and deleting as appropriate.