Reputation: 15
Im trying to get some vba code to run if cell l1's date has already passed. However im am getting a run time error 91. The code i am using is as follows but something is not quite right with the variables which unfortunately despite my efforts i cannot solve.
Sheets("HAULAGE PLANNER").Activate
Dim FoundCell As Object
Set FoundCell = Range("L1").Find(what:=Date)
If FoundCell = ("<= Today") Then
Run.Module1.nextweek
Else: Exit Sub
End If
End Sub
Upvotes: 0
Views: 191
Reputation: 6829
Will move my comment to an answer.
If you are looking at a specific cell, you don't need to .find(). If Range("L1").Value <= Now() Then would suffice.
You may also need to check that L1
is in fact a date, so you would use IsDate to check.
Third point, don't use activate... you can just qualify the Sheets()
for the cell reference.
Mock-up of your code with above changes (untested):
Dim DateCell As Range
Set DateCell = Sheets("HAULAGE PLANNER").Range("L1")
If Not IsDate(DateCell.Value) Then Exit Sub
If DateCell.Value <= Now() Then Application.Run("Module1.nextweek")
Upvotes: 3