Deleting Row by date criteria

  • Thread starter Thread starter martyn
  • Start date Start date
M

martyn

Hi,

I want to automate a file so that when a date in a row matches th
system date, Excel will automatically delete that row. All date are i
column D.

Thanks

Martyn............:rolleyes
 
Hi
try
Sub delete_rows()
Dim RowNdx As Long
Dim LastRow As Long

LastRow = ActiveSheet.Cells(Rows.Count, "D").End(xlUp).row
For RowNdx = LastRow To 1 Step -1
If Cells(RowNdx, "D").Value = now
Rows(RowNdx).Delete
End If
Next RowNdx
End Sub
 
"Now" should be replaced by "Date" unless you really want to match to a
precision greater than one second.

if the dates in the column also contain times, then you would need

If clng(Cells(RowNdx, "D").Value2) = Date

and in any event, you need to add Then on the end of the IF check.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top