Is there a way to Clear or delete data from a spreadsheet Columns A thru H if let's say the date is less then Yesterday? I would prefer to clear the cells. If so How would I do that?
Is there a way to Clear or delete data from a spreadsheet Columns A thru H if let's say the date is less then Yesterday? I would prefer to clear the cells. If so How would I do that?
Last edited by ajames420; 08-27-2007 at 07:01 AM.
Sure, what column's the date in?
p45cal
Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.
The column the date is in is "(F4:F1625)" The date is formatted as 8/27/2007
[vba]
Public Sub ProcessData()
Const TEST_COLUMN As String = "F" '<=== change to suit
Dim i As Long
Dim iLastRow As Long
With ActiveSheet
iLastRow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
For i = 1 To iLastRow 'iLastRow to 1 Step -1
If .Cells(i, TEST_COLUMN).Value < Date - 1 Then
.Cells(i, "A").Resize(, h).ClearContents
End If
Next i
End With
End Sub
[/vba]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
When I open up the VBA Editor where to I put that? At the top of the User Form Code or in the ThisWorkBook?
Sorry
When you open the VBE, insert a new module, one way is to:
Alt+I then M
which takes you through the menus:
Try also:[vba]Sub blah()
For Each cll In Range("F4:F1625").Cells
If cll.Value < (Date - 1) And IsDate(cll.Value) Then Cells(cll.Row, 1).Resize(, 8).ClearContents
Next
End Sub
[/vba]You could also try replacing the If.. line with one ofthe folowing: [vba]If cll.Value < (Date - 1) And IsDate(cll.Value) Then Range(cll.Offset(, -5), cll.Offset(, 2)).ClearContents
[/vba][vba]If cll.Value < (Date - 1) And IsDate(cll.Value) Then Range(Cells(cll.Row, 1), Cells(cll.Row, 8)).ClearContents
[/vba]They all do the same thing in this instance but one may be easier to adapt for differing scenarios
p45cal
Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.
Thank you. They all work great.