Help! - CInt in excel 2010 throws error.

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:

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
Please help me proceed with this code in excel 2010.

Thanks in advance.

Grim.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Which line is causing the error and what are the values of Date1(UBound(Date1)) and Date2(UBound(Date2)) when it occurs?
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,186
Members
449,071
Latest member
cdnMech

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