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.
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.