I need a faster way to verify if a date is between two dates

OWing

New Member
Joined
Nov 29, 2017
Messages
4
Hello,

I have a table and need to check whether each cell in a row satisfies a certain condition. One of the rows has a date. The date might need to satisfy an upper bound or lower bound. Moreover, the comparison might need to be strict(< or >) or not (<= or >=). I have the ability to encode how the condition is presented. I chose to do it this in a format like this "[1/1/1999,1/1/2001]", which is meant to be read as "not-strictly between 1/1/1999 and 1/1/2001." If no lower bound or upper bound is needed, I use "*" in the place of the left or right date, respectively. "(" or ")" is strict, and "[" or "]" is not strict.

DateString = "[1/1/1999,1/1/2001]"
For i = 1 To 250000
DateCondition = Split(DateString, ",", -1)
If Right(DateCondition(0), 1) <> "*" Then
If Left(DateCondition(0), 1) = "(" And Selection.Value <= CDate(Right(DateCondition(0), Len(DateCondition(0)) - 1)) Then
TestBoolean = False
GoTo NextCondition
ElseIf Left(DateCondition(0), 1) = "[" And Selection.Value < CDate(Right(DateCondition(0), Len(DateCondition(0)) - 1)) Then
TestBoolean = False
GoTo NextCondition
End If
End If
If Left(DateCondition(1), 1) <> "*" Then
If Right(DateCondition(1), 1) = ")" And Selection.Value >= CDate(Left(DateCondition(1), Len(DateCondition(1)) - 1)) Then
TestBoolean = False
GoTo NextCondition
ElseIf Right(DateCondition(1), 1) = "]" And Selection.Value > CDate(Left(DateCondition(1), Len(DateCondition(1)) - 1)) Then
TestBoolean = False
GoTo NextCondition
End If
End If
NextCondition:
Next i

Here is the code inside of a time test I wrote to evaluate the condition. it runs slower than desired. Any tips on how to improve this code or better encode the date conditions would be appreciated.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Sorry, I think the first two sentences in my first post are confusing.

I have a table and for each row, I need to check whether each cell in the row satisfies a certain condition. The first cell of each row has a date.
 
Upvote 0

Forum statistics

Threads
1,215,237
Messages
6,123,811
Members
449,127
Latest member
Cyko

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