delete row if timestamp is less then the stated timestamp

SWAY14

New Member
Joined
Jul 27, 2022
Messages
15
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
  2. MacOS
Hello,
So I have VBA code that deletes rows if its not current date. Im trying to modify it to delete if timestamp is less than stated timestamp. but the issue is that it also deletes timestamps greater then the stated timestamp.

this is the code
Option Explicit
Sub testtime()

Application.ScreenUpdating = False

Dim i As Long, lr As Long, ws2 As Worksheet
Set ws2 = Sheets("Sheet2")
lr = ws2.Range("A" & Rows.Count).End(xlUp).Row

For i = lr To 2 Step -1
If ws2.Cells(i, 1).Value < ("17:00:00") Then
ws2.Cells(i, 1).EntireRow.Delete
End If
Next i

Application.ScreenUpdating = True

End Sub

Screen Shot 2022-10-04 at 10.45.40 PM.png

this is what my table stamp time is

any suggestions or help is greatly appreciated
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Like this?
use TIME(17,0,0) for timestamp "17:00:00"
Employ column ZZ to write value, then delete
VBA Code:
Option Explicit
Sub timestamp()
Dim lr&, ws2 As Worksheet
Set ws2 = Sheets("Sheet2")
Application.ScreenUpdating = False
lr = ws2.Cells(Rows.Count, "A").End(xlUp).Row
With ws2.Range("Zz2:Zz" & lr)
    .Value = Evaluate("=1/(MOD(A2:A" & lr & ",1)-TIME(17,0,0)>=0)")
    .SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Delete
    .ClearContents
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,665
Members
449,091
Latest member
peppernaut

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