Dropping to bottom of column, then delete each row with specific Time

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
946
Office Version
  1. 2016
Platform
  1. Windows
Hello All
I have:

dim r as long

VBA Code:
With Sheets("HV-3")
For r = sht.Cells(sht.Rows.Count, "B").End(xlUp)
    If (sht.Cells(r, "B").Value) >= "03:00:00 AM" Then sht.Rows(r).Delete
    End If
    Next r
    End With
Next sht

What I am trying to do, and not working as usual, Is drop to the bottom of Column B,
Work back up one row at at a time
delete each entire row with a date stamp of greater than 3:00 in the morning
For example, lets say "B47" has a date stamp of 03:01:00 AM, then that row would be deleted because it is greater than 03:00:00 AM.
There is a catch, once the code got to the first 03:00:00, it would stop, if not, it would continue up and delete many rows I need.
So, if the code goes to the bottom of a date (In column A) of say 1-11-2022. it would stop deleting at that date when it got to 1-11-2022 at 03:00:00
Can someone help please
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hello All
I have:

dim r as long

VBA Code:
With Sheets("HV-3")
For r = sht.Cells(sht.Rows.Count, "B").End(xlUp)
    If (sht.Cells(r, "B").Value) >= "03:00:00 AM" Then sht.Rows(r).Delete
    End If
    Next r
    End With
Next sht

What I am trying to do, and not working as usual, Is drop to the bottom of Column B,
Work back up one row at at a time
delete each entire row with a date stamp of greater than 3:00 in the morning
For example, lets say "B47" has a date stamp of 03:01:00 AM, then that row would be deleted because it is greater than 03:00:00 AM.
There is a catch, once the code got to the first 03:00:00, it would stop, if not, it would continue up and delete many rows I need.
So, if the code goes to the bottom of a date (In column A) of say 1-11-2022. it would stop deleting at that date when it got to 1-11-2022 at 03:00:00
Can someone help please
Sorry, should not have a "Next SHT"
 
Upvote 0
Still looking for a little help here...anyone?
 
Upvote 0
maybe
VBA Code:
With Sheets("HV-3")
    For r = .Cells(.Rows.Count, "B").End(xlUp).Row To 1 Step -1
        If (.Cells(r, "B").Value) >= TimeSerial(3, 0, 0) Then     ' 3:00:00 AM
            .Rows(r).Delete
        Else
            Exit For
        End If
    Next r
End With
 
Upvote 0
Try:
VBA Code:
Sub delete()
Dim Lr&, i&
With Sheets("HV-3")
    Lr = .Cells(Rows.Count, "B").End(xlUp).Row
    For i = Lr To 2 Step -1
        If .Cells(i, "B") <= TimeSerial(3, 0, 0) Then
            Exit Sub
        Else
            .Cells(i, "B").EntireRow.delete
        End If
    Next
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,854
Members
449,096
Latest member
Erald

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