I have a small macro where I need delete all rows with dates:
Code:
Sub allDates()
Dim i As Long
For i = 1 To Cells.SpecialCells(xlCellTypeLastCell).Row
Debug.Print Cells(i, "a").Value
If Cells(i, "a") < "6/1/2010" Then
Cells(i, "a").EntireRow.Delete
End If
Next i
End Sub
The macro doesn't seem to always delete dates. Could this be because the worksheet contains blank rows? The row with date is actually merged.
Sample Worksheet Data
Code:
--------------------------------------------------------------------------------
Submitted
4/1/2010
Production Production Number
THE DEAL-BDEA-09056 BDEA-09056
CENTRIC HITS-CH030210 CH030210
------------------------------------------------------------
Submitted
4/6/2010
Production Production Number
INFLUENCES-JIFA0708 - TAKE 6 JIFA0708
I tried the macro above with CDate in the following:
Code:
If CDATE(Cells(i, "a")) < CDATE("6/1/2010") Then
I received a type mismatch error.
I also tried:
Code:
If VALUE(Cells(i, "a")) < VALUE("6/1/2010") Then
and other things within my spreadsheet seemed to be erased.
Is there another alternative?
2. I need for this macro to run in the background when the user pastes the contents into excel worksheet (the data comes from a website). The date will change constantly. How can the date be changed on the fly for each report?
thanks in advance.