The following macro works as it was designed:
Sub Test3()
Dim ReportEndDate As Date
With Worksheets(“Paste New Data Here”)
ReportEndDate = .Cells(.UsedRange.Rows.Count – 1, 2)
End With
ActiveCell.FormulaR1C1 = _
“=IF(AND(RC[-1]>=Today()-30,RC[-1]<TODAY()),RC[-1],"""")"
End Sub
The variable ReportEndDate gets its date value from a specific cell on the Paste New Data Here worksheet. The IF/AND function calculates correctly.
However, my problem is that when I attempt to use the variable ReportEndDate in place of the TODAY() function, I get run time errors. What I am trying to do is to calculate the ReportEndDate against the date in the previous column. When I do this using the TODAY() function it works. When I try to do this using ReportEndDate , it doesn't.
Can anyone tell me what I'm doing wrong?
Thanks in advance…