• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Need help for macro creation

mfvc

New Member
Hey guys,

I'm trying to create a macro to clear the cells of past dates. Imagine you have a table with all the different dates and number for these date: once the date is past the current date indicated in a cell, I would like all the past cell date to clear (as in the corresponding number and not the date) once the "today date" is updated

For now I have this: worksheets("Sheet1").Range("C4,D4,E4,F4,G4,H4").ClearContents
but I don't know how to link it to the current cell date and the table. I hope I'm making myself clear
 
Try:
Code:
Dim c As Range
Dim ws As String
ws = "Sheet1"

For Each c In Worksheets(ws).Range("C4,D4,E4,F4,G4,H4")
  If c.Value < Int(Now()) Then c.ClearContents
Next
 
Try:
Code:
Dim c As Range
Dim ws As String
ws = "Sheet1"

For Each c In Worksheets(ws).Range("C4,D4,E4,F4,G4,H4")
  If c.Value < Int(Now()) Then c.ClearContents
Next

Actually the date range is not what needs to be cleared but another row of the forecasted data according to the day. It works if I use this:
If [C2] < [A1] Then
result = Worksheets("Sheet1").[C3].ClearContents
End If
Range("C3").ClearContents

(A1 being the date of today, C2 the date in the row and C3 the forecasted sales)
The problem is I have a very large amount of data and it would take a lot of time to do it for every cell. But thank you for responding so quickly!
 
Back
Top