"Conversion from string "" to type 'Date' is not valid." in

Posted on 2007-08-10
Last Modified: 2013-11-27
I am getting the error "Conversion from string "" to type 'Date' is not valid." from the following line of code:

If oSheet.Cells(i, 6).value = "" Then Exit For

What I am doing is adding values from excel into a CheckedListbox. The values are dates, and the line above is just to check to make sure that the excel cell is not blank. It worked fine for stings and values, but dates it is getting hung up on. Any ideas how to fix this?
Question by:tiehaze
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    If oSheet.Cells(i, 6).value.ToString() = "" Then Exit For

    Author Comment

    I am getting the following error now:

    {"Object reference not set to an instance of an object."}
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    but I guess not for the same cell/line?
    please specify

    Author Comment

    no... I am adding dates from an excel spreadsheet to a checkedlistbox. I need to check if the cell is blank, and if it is, I used the Exit For statement.

    Like I said, it works when the data is strings or numbers, but dates are not working.
    LVL 46

    Accepted Solution

    Hi tiehaze,

    Try perhaps using the Text property....

        If oSheet.Cells(i, 6).Text = "" Then Exit For



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
    Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

    761 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

    8 Experts available now in Live!

    Get 1:1 Help Now