How use dates as criteria in VBA

JayhawkRacer

New Member
Joined
Feb 24, 2014
Messages
4
I apologize if this is simple or has been asked. I couldn't find the answer from an extensive search here and other communities.

I'm attempting to use VBA to edit column 12 in each row that meets the following criteria:

Column 16 is a specific text string ("name")
Column 11 is a specific text string ("RESCHED IN")
Column 12 is tomorrow, today, or in the past (anything after tomorrow should remain unedited)

Here's the code I'm trying so far, but obviously the "date+1" is a terrible idea and doesn't work. Any ideas?

Code:
    LastRow = Range("C65536").End(xlUp).Row
    For c = LastRow To 2 Step -1
        If Cells(c, 16) = "name" And Cells(c, 11) = "RESCHED IN" And (Cells(c, 12) < "Date" Or Cells(c, 12) = "Date" Or Cells(c, 12) = "Date+1") Then
            Cells(c, 12).FormulaR1C1 = "=Today()+2"
        End If
    Next c

The
Code:
Cells(c, 12).FormulaR1C1 = "=Today()+2"
part works, but it completely ignores any of my date criteria and just makes column 12 Today+2 days for anything that meets the "name" and "RESCHED IN" criteria.
 
Last edited:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Anything that you put between quotes is treated as literal text. So your formula is not checking the dates, it is actually referring to the string "Date".
Replace all this part:
Code:
(Cells(c, 12) < "Date" Or Cells(c, 12) = "Date" Or Cells(c, 12) = "Date+1")
with just this:
Code:
Cells(c,12) < (Date + 1)
 
Upvote 0
Anything that you put between quotes is treated as literal text. So your formula is not checking the dates, it is actually referring to the string "Date".
Replace all this part:
Code:
(Cells(c, 12) < "Date" Or Cells(c, 12) = "Date" Or Cells(c, 12) = "Date+1")
with just this:
Code:
Cells(c,12) < (Date + 1)

This worked perfectly! Thank you so much!
 
Upvote 0
You are welcome!
Glad to help!:)
 
Upvote 0

Forum statistics

Threads
1,215,500
Messages
6,125,166
Members
449,210
Latest member
grifaz

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