Delete rows if cell value is greater than a specific time

Rackette

New Member
Joined
Jul 2, 2019
Messages
37
Hello again!
Hopefully, today was a pleasant day for everyone. Not a perfect one, necessarily, but at least a pleasant one. :)
I thought this would be an easy thing to find, but I can't seem to find any code that will do what I need.

My spreadsheet is only 7 columns by about 300 or 400 rows, so how long it takes to run is not a huge issue.
The 4th column is a date/time column and is in the format like: 9/3/2019 12:01:00 AM
In this date/time column the date will not change throughout the column, BUT the TIME WILL VARY...so all rows will be for the same day but the times will change.
My header row is row 1.
Records start on row 2.
The number of rows is dynamic.

I need to delete all rows where the TIME in column 4 is "less than 0645"

As always, any and all help is appreciated!

-Christine
 
Dante, I"m sorry I was unable to answer your question sooner and ended up wasting your time.

Hi @Rackette, taking advantage of the Trebor code, I adapted it in my code to work and leave a more compact macro.

Code:
Sub Delete_Rows()
Dim lr As Long, i As Long, a, r As Range, exists As Boolean
Application.ScreenUpdating = False
lr = Range("D" & Rows.Count).End(xlUp).Row
Set r = Range("A" & lr + 1)
a = Range("D2:D" & lr)
For i = 1 To UBound(a)
  If Len(a(i, 1)) > 0 Then If TimeSerial(Hour(a(i, 1)), Minute(a(i, 1)), 0) < TimeSerial(6, 45, 0) Then Set r = Union(r, Range("A" & i + 1))
Next i
r.EntireRow.Delete
End Sub
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Dante,
Thank you very much for following up. That does what I need it too, also.
Everyone on here is always so helpful!

-Christine
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

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