Search specific range for date

jackfr0st

New Member
Joined
Apr 8, 2019
Messages
2
I have a pretty simple request, but getting an error with the range.

When the workbook is open, I want to search a specific range ("c2:c15") for any date starting with today and 60 days in the future and popup a msgbox. Below is what I have.

Private Sub Workbook_Open()

If Worksheets("Tests").Range("c2:c15").Value <= Date Then
MsgBox "One of the tests is past due for a review."

ElseIf Worksheets("Tests").Range("c2:c15").Value <= Date + 60 Then
MsgBox "One of the tests needs to be reviewed within the next 60 days."

End If

End Sub
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Welcome to the Board!

You cannot run a formula against a whole range like that. It doesn't make logical sense.
Try looping through the cells in the range, and checking each one, structured something like:
Code:
Dim cell as Range

For each cell in Sheets("Tests").Range("C2:C15")
    If cell.Value <= Date Then...
        ....
    End If
Next cell
 
Upvote 0
Excellent!
You are welcome. Glad I was able to get you on the right track.
:)
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top