Pergunta

I have a userform set up in Excel. It helps me to enter some values into a spreadsheet. I've used the following code numerous times, and every other time value goes its cell correctly. This one always comes up as "TRUE" on the spreadsheet. I don't know what's wrong.

ssheet.Cells(nr, 18) = Me.jobTravelStart

I've even tried

ssheet.Cells(nr, 18) = CDate(Me.jobTravelStart)

and I still get the same thing.

Foi útil?

Solução

Ah, Excel and datetime values... Always fun (or trouble).

Problem is that excel uses one datatype for storing datetime values internally, and uses another to display it (I know, I know, this is technically not correct).

To troubleshoot these kind of problems, always go back to source, so check if the stored data is correct. Either use a Debug.Print statement to output the variable while the code is running, or check the local variables when debugging your code.

When you verified that the source is correct, focus on the display part. As xQbert stated in the comments, check the datatype set for the cell you're using to display the data. Make sure the datatype is correct, BEFORE the data is entered into the cell (if need be, you can explicitly do it in code, but that is quite slow, so do it only if there is no other option).

If all this does not help you, please provide more details on how it fails you and what you have found debugging. People can only help you if you provide enough info.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top