1

I try to get a value from excel and to use in vb.bet but when i try to convert date from Excel my vba display error.

I try this:

Dim Target As DateTime = Nothing
Target = DateTime.ParseExact(currentWorksheet.Cells(CurrentRow, 19).Text, "dd-MMM-yy", System.Globalization.CultureInfo.InvariantCulture)

This code currentWorksheet.Cells(CurrentRow, 19).Text get me 3939344687 value from Excel, my date in excel are 01/26/17.

When i try to convert this number to date i get error.

Another code what i try are :

Target = Convert.ToDateTime(currentWorksheet.Cells(CurrentRow, 19).Text)

But doesn't work.

Tim Williams
  • 154,628
  • 8
  • 97
  • 125
Vladut
  • 647
  • 1
  • 10
  • 35
  • How do you know the date is `01/26/17`, how does it look in Excel, and is there a reason you are using `Text` instead of `Value`? – GSerg Feb 01 '17 at 14:32
  • In Unix time `3939344687` = Sun, 31 Oct 2094 06:24:47 GMT – Robin Mackenzie Feb 01 '17 at 14:35
  • Make sure every time you read/save date, it's always in a date object and never as a string. Make sure the excel cells are set to be dates. – nbadaud Feb 01 '17 at 14:35
  • See here - http://stackoverflow.com/questions/727466/how-do-i-convert-an-excel-serial-date-number-to-a-net-datetime . But your date should look like this: `42761` – Vityata Feb 01 '17 at 14:37

0 Answers0