delete previous rows on date and time

Mr Marvin

New Member
Joined
Sep 8, 2021
Messages
31
Office Version
  1. 2019
Platform
  1. Windows
i all, i have this macro below which deletes all rows from the prev day.

Sub DeleteFromDate()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim LR As Long
LR = ActiveSheet.Range("F" & Rows.Count).End(xlUp).Row
DateR = Application.InputBox("Enter based on date to delete", TitleMsg, FormatDateTime(Date, vbShortDate), Type:=1)
Cells.AutoFilter Field:=6, Criteria1:="<=" & DateR
ALR = ActiveSheet.Range("F" & Rows.Count).End(xlUp).Row
If ALR > 1 Then
Range("F2:F" & LR).SpecialCells(xlCellTypeVisible).Select
Range("F2:F" & LR).Delete
Range("F1").Activate
End If
Cells.AutoFilter
MsgBox "Finished deleting rows"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

on my report i have it sorted on the created date and the column which details the created date and time is shown as e.g. Oct 4, 2021 7.55 PM. with the macro above it removes all rows from the previous day but what i am trying to is expand that and remove any rows that have the created date before 8.00 PM the previous day. So my daily report which i received on the 5th would show all information from the 4th backwards. but i only need the rows from the 3rd, 8.00 PM onwards.


Any help or guidance if this is possible would be greatly appreciated

thanks
 
Can you give me an XL2BB of the 1st 10 rows of your data sheet ? or else a copy of your workbook via Dropbox, Google Drive, Onedrive or any sharing platform ?

Is your date column still F ?
In what row and column does your data start ?
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
hi alek

hi have the header starting in A1 but actual data starts B1 and col F is the created date

AgreementAgr SerialCreated DateEvent Date
214495047302404Oct 10, 2021 6:12 PMOct 10, 2021 6:46 PM
214495037302403Oct 10, 2021 6:09 PMOct 10, 2021 6:11 PM
214494757302373Oct 10, 2021 5:14 PMOct 10, 2021 6:04 PM
214494747302372Oct 10, 2021 5:14 PMOct 10, 2021 5:16 PM
214494517302349Oct 10, 2021 4:52 PMOct 10, 2021 4:59 PM
214494497302347Oct 10, 2021 4:51 PMOct 10, 2021 5:02 PM
214494457302343Oct 10, 2021 4:47 PMOct 10, 2021 4:50 PM
214494427302340Oct 10, 2021 4:46 PMOct 10, 2021 4:52 PM
214494417302339Oct 10, 2021 4:46 PMOct 10, 2021 6:59 PM
 
Upvote 0
I really need to see context. Based on created date being F you are only showing me D:G.
I need to see how A:C are populated as well.

Also the copied in date columns is coming across as text.
Can you confirm that if you change the format of column F to say your standard short date format does the format actually change. If not then it is text at your end, if it does then the copy paste converted it to text and I will need to change it back to a date at my end for testing.
 
Upvote 0
The only way I have been able to reproduce your error is for column 6 to not be within the filter range of columns.
 
Upvote 0
Can you give me an XL2BB of the 1st 10 rows of your data sheet ? or else a copy of your workbook via Dropbox, Google Drive, Onedrive or any sharing platform ?

Is your date column still F ?
In what row and column does your data start ?

this is what it would it be like after, apologies i cant get it on any either way,

test1.PNG
 
Upvote 0
I can't get it to fail.
Do you have the code in a standard module ("not" in sheet module) ?
Also how are you running the code ?
And what is the sheet name the data is on ?

Can you use the VBA button and send me back the code you are actually using ?
 
Upvote 0
hi alek, i have managed to get this working now. many thanks for your assistance on this.
 
Upvote 0
No problem. Glad I could help.
I would be interested to know what you needed to do to get it working though, if you get a chance.
 
Upvote 0

Forum statistics

Threads
1,215,461
Messages
6,124,958
Members
449,200
Latest member
indiansth

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