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

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?
tiehazeAsked:
Who is Participating?
 
Wayne Taylor (webtubbs)Commented:
Hi tiehaze,

Try perhaps using the Text property....

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

Regards,

Wayne
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
If oSheet.Cells(i, 6).value.ToString() = "" Then Exit For
0
 
tiehazeAuthor Commented:
I am getting the following error now:

System.NullReferenceException
{"Object reference not set to an instance of an object."}
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
but I guess not for the same cell/line?
please specify
0
 
tiehazeAuthor Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.