Delete rows from the bottom with the last different date

Mux99

Board Regular
Joined
Apr 15, 2019
Messages
57
Hi all

Is it possible to create a macro to delete the last rows from the bottom of the worksheet with a different date? In the example below I would need it to select and delete from rows 1161 to the end. The data will always be in column A and there will be multiple dates (probably 7 or 14) with different times.

6j0k8x.jpg


Thanks in advance
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Code:
[COLOR="Navy"]Sub[/COLOR] MG16Apr57
[COLOR="Navy"]Dim[/COLOR] Lst [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Dt [COLOR="Navy"]As[/COLOR] Date, nDt [COLOR="Navy"]As[/COLOR] Date
Lst = Range("A" & Rows.Count).End(xlUp).Row
Dt = Int(Cells(Lst, 1)): nDt = Dt
[COLOR="Navy"]Do[/COLOR] [COLOR="Navy"]While[/COLOR] nDt = Dt
    Cells(Lst, 1).ClearContents
    Lst = Lst - 1
    nDt = Format(Cells(Lst, 1), "dd/mm/yyyy")
[COLOR="Navy"]Loop[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
This may be better as I forgot to amend all of the code when I saw your date format !!!
Code:
[COLOR="Navy"]Sub[/COLOR] MG16Apr09
[COLOR="Navy"]Dim[/COLOR] Lst [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Dt [COLOR="Navy"]As[/COLOR] Date, nDt [COLOR="Navy"]As[/COLOR] Date
Lst = Range("A" & Rows.Count).End(xlUp).Row
Dt = Int(Cells(Lst, 1)): nDt = Dt
[COLOR="Navy"]Do[/COLOR] [COLOR="Navy"]While[/COLOR] nDt = Dt
    Cells(Lst, 1).ClearContents
    Lst = Lst - 1
    nDt = Int(Cells(Lst, 1))
[COLOR="Navy"]Loop[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
This may be better as I forgot to amend all of the code when I saw your date format !!!
Code:
[COLOR=Navy]Sub[/COLOR] MG16Apr09
[COLOR=Navy]Dim[/COLOR] Lst [COLOR=Navy]As[/COLOR] [COLOR=Navy]Long,[/COLOR] Dt [COLOR=Navy]As[/COLOR] Date, nDt [COLOR=Navy]As[/COLOR] Date
Lst = Range("A" & Rows.Count).End(xlUp).Row
Dt = Int(Cells(Lst, 1)): nDt = Dt
[COLOR=Navy]Do[/COLOR] [COLOR=Navy]While[/COLOR] nDt = Dt
    Cells(Lst, 1).ClearContents
    Lst = Lst - 1
    nDt = Int(Cells(Lst, 1))
[COLOR=Navy]Loop[/COLOR]
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
Regards Mick

Thanks for this. I replaced .ClearContents with .EntireRow.Delete and it worked great.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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