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

Posted on 2011-10-10
Last Modified: 2012-05-12
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!

Question by:RobStl
    LVL 59

    Accepted Solution


    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


    Author Comment

    Oh, duh... lol. Silly mistake, thank you for noticing this for me!  


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Suggested Solutions

    Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
    This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
    The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
    This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now