grimreeper
New Member
- Joined
- Feb 12, 2013
- Messages
- 13
Hey guys,
I am trying to compile a code in excel 2010 and the usage on CInt throws an error - Run time error '13' type mismatch. It used to run on excel 2007 without any issues.But Now I have switched to 2010. Please help.
Input is start date and end date (ie start - June 8th and end - June 14th) The cell format is text format.
Code -
VB:
Please help me proceed with this code in excel 2010.
Thanks in advance.
Grim.
I am trying to compile a code in excel 2010 and the usage on CInt throws an error - Run time error '13' type mismatch. It used to run on excel 2007 without any issues.But Now I have switched to 2010. Please help.
Input is start date and end date (ie start - June 8th and end - June 14th) The cell format is text format.
Code -
VB:
Code:
Function DateCompare(Date1 As Variant, Date2 As Variant) As Integer
'compare years (greater year = more recent)
If CInt(Date1(UBound(Date1))) > CInt(Date2(UBound(Date2))) Then
DateCompare = 1
ElseIf CInt(Date2(UBound(Date2))) > CInt(Date1(UBound(Date1))) Then
DateCompare = -1
'compare months (greater month = more recent (don't need to worry about December/January, handled with year))
ElseIf CInt(Date1(LBound(Date1))) > CInt(Date2(LBound(Date2))) Then
DateCompare = 1
ElseIf CInt(Date2(LBound(Date2))) > CInt(Date1(LBound(Date1))) Then
DateCompare = -1
'compare days (greater day = more recent)
ElseIf CInt(Date1(LBound(Date1) + 1)) > CInt(Date2(LBound(Date2) + 1)) Then
DateCompare = 1
ElseIf CInt(Date2(LBound(Date2) + 1)) > CInt(Date1(LBound(Date1) + 1)) Then
DateCompare = -1
'Dates are equal, arbitrarily return date one
Else
DateCompare = 0
End If
End Function
Thanks in advance.
Grim.