IF .. then DATE comparison

instanceoftime

Board Regular
Joined
Mar 23, 2011
Messages
78
I'm looking to use a macro and not a formula to do delete old invoices automatically. please help

if today is greater than 2/1/2019 then delete column A
 

Some videos you may like

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,743
Office Version
  1. 365
Platform
  1. Windows
ONE of these lines should be all you need

Test on a COPY of your workbook!

Do you want to delete values or the column ?
Is 2/1/2019 2nd January (UK) or 1st February (USA) ?

DELETE VALUES
Code:
[I][COLOR=#006400]2nd January 2019[/COLOR][/I]
    If Date > DateSerial(2019, 1, 2) Then ActiveSheet.Columns("A").ClearContents
[I][COLOR=#006400]1st February 2019[/COLOR][/I]
    If Date > DateSerial(2019, 1, 2) Then ActiveSheet.Columns("A").ClearContents
DELETE COLUMN
Code:
[I][COLOR=#006400]2nd January 2019[/COLOR][/I]
   If Date > DateSerial(2019, 1, 2) Then ActiveSheet.Columns("A").Delete
[I][COLOR=#006400]1st February 2019[/COLOR][/I]
    If Date > DateSerial(2019, 1, 2) Then ActiveSheet.Columns("A").Delete
 

instanceoftime

Board Regular
Joined
Mar 23, 2011
Messages
78
Awesome... worked perfect


ONE of these lines should be all you need

Test on a COPY of your workbook!

Do you want to delete values or the column ?
Is 2/1/2019 2nd January (UK) or 1st February (USA) ?

DELETE VALUES
Code:
[I][COLOR=#006400]2nd January 2019[/COLOR][/I]
    If Date > DateSerial(2019, 1, 2) Then ActiveSheet.Columns("A").ClearContents
[I][COLOR=#006400]1st February 2019[/COLOR][/I]
    If Date > DateSerial(2019, 1, 2) Then ActiveSheet.Columns("A").ClearContents
DELETE COLUMN
Code:
[I][COLOR=#006400]2nd January 2019[/COLOR][/I]
   If Date > DateSerial(2019, 1, 2) Then ActiveSheet.Columns("A").Delete
[I][COLOR=#006400]1st February 2019[/COLOR][/I]
    If Date > DateSerial(2019, 1, 2) Then ActiveSheet.Columns("A").Delete
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,743
Office Version
  1. 365
Platform
  1. Windows
thanks for your feedback
(y)
 

Watch MrExcel Video

Forum statistics

Threads
1,108,956
Messages
5,525,883
Members
409,669
Latest member
JDCupps

This Week's Hot Topics

Top