• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1497
  • Last Modified:

Excel VBA Run-Time Error 13: Type Mismatch when Comparing Dates

Hey guys,

I have been searching through multiple run-time error 13: type mismatch issues, but still cannot find out why my example is not working.  I am simply comparing dates passed to a function, but cannot figure out why I am getting the run-time error 13: type mismatch error.  See the following code:
public startDate, endDate As Date

Sub Test()
Dim projectStartDate, projectEndDate As Date
Dim objectWidth As Integer

startDate = CDate("10/1/2011")
endDate = CDate("1/1/2012")

projectStartDate = CDate("8/1/2011")
projectEndDate = CDate("2/1/2012")
objectWidth = determineObjectWidth(projectStartDate, projectEndDate)

End Sub

Function determineObjectWidth(ByVal projectStartDate As Date, ByVal projectEndDate As Date) As Integer
Dim oneMonthVariable As Integer
oneMonthVariable = 100
If ((projectStartDate <= startDate) & (projectEndDate >= endDate)) Then  'Run Type Error 13: Type Mismatch HERE

determineObjectWidth = 8 * oneMonthVariable

End if

End Function

Open in new window


Could somebody explain why this run-time error is occuring?  Thanks in advance!

Regards,
Rob
0
RobStl
Asked:
RobStl
1 Solution
 
Saurabh Singh TeotiaCommented:

In line 19 you have use apostrophe &... change the same to And and it will work..what i mean is this...

If ((projectStartDate <= startDate) And (projectEndDate >= endDate)) Then

Saurabh...
0
 
RobStlAuthor Commented:
Oh, duh... lol. Silly mistake, thank you for noticing this for me!  

~Rob
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now