ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Deleting entries one year old (https://www.excelbanter.com/excel-discussion-misc-queries/165744-deleting-entries-one-year-old.html)

AOP

Deleting entries one year old
 
I have the following code which deletes all entries that are one year old to
date.

Private Sub deleteit()
Dim LastRow As Long
Dim X
LastRow = Range("A20000").End(xlUp).Row

For X = LastRow To 1 Step -1
If Cells(X, 1).Value < Date - 365 Then
Range("A" & X & ":P" & X).ClearContents
End If
Next
End Sub

This code works well, but what I need is only to clear columns A to F and H.
I need it to leave column G alone because it has formulas.

--
AOP

JW[_2_]

Deleting entries one year old
 
One way:
Range("A" & X & ":F" & X & ",H" & X).ClearContents

AOP wrote:
I have the following code which deletes all entries that are one year old to
date.

Private Sub deleteit()
Dim LastRow As Long
Dim X
LastRow = Range("A20000").End(xlUp).Row

For X = LastRow To 1 Step -1
If Cells(X, 1).Value < Date - 365 Then
Range("A" & X & ":P" & X).ClearContents
End If
Next
End Sub

This code works well, but what I need is only to clear columns A to F and H.
I need it to leave column G alone because it has formulas.

--
AOP



AOP

Deleting entries one year old
 
Thanks that works well
--
AOP


"JW" wrote:

One way:
Range("A" & X & ":F" & X & ",H" & X).ClearContents

AOP wrote:
I have the following code which deletes all entries that are one year old to
date.

Private Sub deleteit()
Dim LastRow As Long
Dim X
LastRow = Range("A20000").End(xlUp).Row

For X = LastRow To 1 Step -1
If Cells(X, 1).Value < Date - 365 Then
Range("A" & X & ":P" & X).ClearContents
End If
Next
End Sub

This code works well, but what I need is only to clear columns A to F and H.
I need it to leave column G alone because it has formulas.

--
AOP





All times are GMT +1. The time now is 01:02 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com