Link to home
Start Free TrialLog in
Avatar of EdLB
EdLB

asked on

Executing a conditional date check in vba

The value in X2 is a string date. The following code returns a value of "FALSE" in B2. I want it to execute the if statement and return a 1 or 0.

Dim EndDate As Date
 
EndDate = "1/1/2016"

Worksheets("PO_List").Range("B2").Formula= "=If(" & DateValue(Range("X2")) <= DateValue(EndDate) & ",1,0)"
Avatar of Haris Dulic
Haris Dulic
Flag of Austria image

Hi

try something like this:

Dim EndDate As Date
Dim tmpF As String
 
EndDate = "1/1/2016"

tmpF = "=IF(" & DateValue(Range("X2")) & " <= DateValue(""" & EndDate & """)" & ",1,0)"

Worksheets("PO_List").Range("B2").Formula = tmpF

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of EdLB
EdLB

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of EdLB
EdLB

ASKER

Very simple, straightforward and it works.