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>
 
What is the point of worrying about column K if the first part does not work?
You say that this is Urgent, but you continually fail to answer my questions.
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Please read post#17, you have not answered that question. Nor seemingly taken onboard what I said about not being able to see your screen and thus needing you to give me the information I need in order to help you.
 
Upvote 0
This code unfilters everything and nothing happens. It doesnt filter column J for future date

Sub exceluser9()
With Sheets("Delete")
.Range("$A$1:$K$10000").AutoFilter 10, ">" & CLng(Date)
End With
End Sub
 
Upvote 0
Hi Fluff,

Im using this code it works fine but it deletes blank cells as well, could you amend to skip blank?

Sub DeleteRowBasedOnDateRange()


Dim spem As Workbook
Dim ws As Worksheet
Dim N As Long, I As Long


Set spem = Excel.Workbooks("Testing VBA.xlsm")
Set ws = spem.Worksheets("Sheet1")


N = ws.Cells(ws.Rows.Count, "K").End(xlUp).Row


For I = N To 2 Step -1
If ws.Cells(I, "K").Value > Date Then
ws.Rows(I).Delete
End If
Next I


End Sub
 
Upvote 0
Try
Code:
If ws.Cells(i, "K").Value > Date And ws.Cells(i, "K") <> "" Then
 
Upvote 0
Thanks Fluff.

Also users will save the sheet as per their preference.

Do we have to change below code as well?

Set spem = Excel.Workbooks("Testing VBA.xlsm")
 
Upvote 0
If the code is in that workbook then change it to
Code:
Sub DeleteRowBasedOnDateRange()
Dim ws As Worksheet
Dim N As Long, I As Long


Set ws = ThisWorkbook.Worksheets("Sheet1")


N = ws.Cells(ws.Rows.Count, "K").End(xlUp).Row


For I = N To 2 Step -1
 
Upvote 0
Hi Fluff,

Im using below code and nothing happens. Its not deleting rows

Sub DeleteRowBasedOnDateRange()


Dim ws As Worksheet
Dim N As Long, I As Long




Set ws = ThisWorkbook.Worksheets("Sheet1")


N = ws.Cells(ws.Rows.Count, "K").End(xlUp).Row




For I = N To 2 Step -1
If ws.Cells(i, "K").Value > Date And ws.Cells(i, "K") <> "" Then
ws.Rows(I).Delete
End If
Next I




End Sub
 
Upvote 0
Is the code in the same workbook as the sheet where you want to delete the rows?
 
Upvote 0

Forum statistics

Threads
1,216,040
Messages
6,128,454
Members
449,455
Latest member
jesski

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