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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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,214,786
Messages
6,121,546
Members
449,038
Latest member
Guest1337

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