VBA delete rows if time is more than 9:30:00

cazdealer

Board Regular
Joined
Mar 12, 2011
Messages
96
Hi,

I have this sort of Data from row 1 to row 9999


A B C
200 22.95 09:28:47 AM
300 56.67 09:29:32 AM
200 12.75 09:30:06 AM
100 75.97 09:32:47 AM
200 22.95 09:49:00 AM
etc...

I want to find a way the create a VBA procedure that would delete all the rows that the time in column C is over 09:30:00 AM

I have tried to convert the time into a number and then if formula to see if the number is higher than 0.3958333 but it doesn't work :(

any other ideas?
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Can you filter the 3 columns and do a "greater than" criteria on it? You could then show everything but that and select all visible rows and delete them. Hope this helps.
 
Upvote 0
Are your times in column C time only?
Or are they Date AND Time?

Format column C as Number, with several decimal places.
Are they showing as
0.xxxxx

or do they have whole numbers as well like:
40875.xxxxx
 
Upvote 0
yes, they are time only in column C (not date and time)

when I convert them, they become something like 0.395625 or 0.395636574074074
 
Upvote 0
Try

Code:
Sub Foo()
Dim i As Long, lr As Long
 
lr = Cells(Rows.Count, "C").End(xlUp).Row
 
For i = lr To 1 Step -1
    With Cells(i, "C")
        If IsNumeric(.Value) And .Value > TimeSerial(9, 30, 0) Then Rows(i).EntireRow.Delete
    End With
Next i
End Sub
 
Upvote 0
Code:
Sub tester()
lastRow = Cells(1).End(xlDown).Row
s1 = TimeValue("9:30 am")
For i = lastRow To 1 Step -1
s = Cells(i, 3)
If s > s1 Then Rows(i).Delete
Next i
End Sub

going backwards saves having to renumber i
everytime a row is deleted.
 
Upvote 0

Forum statistics

Threads
1,214,560
Messages
6,120,222
Members
448,951
Latest member
jennlynn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top