VBA code required to delete rows with future dates - Urgent

exceluser9

Active Member
Joined
Jun 27, 2015
Messages
388
Hi Team,

I have a data column J and K with formula =IFERROR(IF(G3<>"",WORKDAY(G3,3),""),"") in column J and =IFERROR(IF(H3<>"",WORKDAY(J3,2),""),"") in column K.

I need a vba code to delete the entire row if column "J" has future date, it should retain current date and past date.

And it should also delete entire row if column "K" has a future date (Retain if it has todays date & past date) only if column "H" contains today's date or past date.

If column J & K is blank please retain record.

Column GColumn H Column JColumn K
06-08-201908-08-2019 09/08/201913/08/2019
05-08-201907-08-2019 08/08/201912/08/2019
07-08-2019 12/08/2019
07-08-2019 12/08/2019
07-08-2019 12/08/2019
07-08-2019 12/08/2019
07-08-2019 12/08/2019
07-08-2019 12/08/2019
07-08-2019 12/08/2019
07-08-2019 12/08/2019
07-08-2019 12/08/2019
07-08-2019 12/08/2019

<colgroup><col><col span="2"><col span="2"></colgroup><tbody>
</tbody>
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Turn on the macro recorder, filter on column J for future dates & then delete the visible rows.
Turn of the recorder & you have your code.
 
Upvote 0
Hi Fluff,

What about logic in column K?

Dates will keep on changing, recording didn't work.

Could you help with VBA code.
 
Upvote 0
I don't understand you logic for column K also what do you want to happen for the 2nd row of data you posted?
Please also post the recorded macro & explain why it "didn't work"
 
Upvote 0
Hi Fluff,

What about logic in column K?

Dates will keep on changing, recording didn't work.

Could you help with VBA code for logic and deletion.
 
Upvote 0
Hi Fluff,

Row 2 should be deleted since column K has a future date and there is a past date in column H.

Logic 1 - I need a vba code to delete the entire row if column "J" has future date in row (Retain current date and past date)

Logic 2 - Delete entire row if column "K" has a future date only if a date is found in column "H" row (Retain current date and past date)

Logic 3 - If column J and K is blank do not delete the rows.

Tried recording it didnt work. Below is the code.

Sheets("Delete").Select
Cells.Select
Selection.AutoFilter
Range("J1").Select
ActiveSheet.Range("$A$1:$K$10000").AutoFilter Field:=10, Operator:= _
xlFilterValues, Criteria2:=Array(2, "8/12/2019")
End Sub

Could you help please, i dont think recording would work.
 
Upvote 0
Below is a example with comments

Column GColumn H Column JColumn KComments
02-08-201908-08-2019 07/08/201909/08/2019Do not delete
05-08-201907-08-2019 08/08/201912/08/2019Delete
Do not delete
02-08-2019 07/08/2019 Do not delete
02-08-2019 07/08/2019 Do not delete
02-08-2019 07/08/2019 Do not delete
02-08-2019 07/08/2019 Do not delete
02-08-2019 07/08/2019 Do not delete
07-08-2019 12/08/2019 Delete
02-08-2019 07/08/2019 Do not delete
02-08-2019 07/08/2019 Do not delete
02-08-2019 07/08/2019 Do not delete
02-08-2019 07/08/2019 Do not delete

<colgroup><col><col span="2"><col span="2"><col></colgroup><tbody>
</tbody>
 
Upvote 0
Ok, does this correctly filter col J?
Code:
Sub exceluser9()
With Sheets("Delete")
   .Range("$A$1:$K$10000").AutoFilter 10, ">" & CLng(Date)
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,497
Members
448,967
Latest member
visheshkotha

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