Having problem getting date into format: yyyy/mm/dd

A

Andrew

I am trying to format the contents of a cell to display
the date in the format: yyyy/mm/dd

Right now in the code I have:

OutputSheet.Cells(OutputRowCounter - NumTrans - 2,
5).Value = Format(Input1Sheet.Cells(2,
4).Value, "yyyy/mm/dd")

What ends up happening is that it formats the variable
properly, but when it writes it to the cell Excel changes
the date back to mm/dd/yyyy.

How do I get my change to stick?
 
J

J.E. McGimpsey

XL will still parse whatever string VBA hands it (just as if you
typed it in), then display the value per the cell's format, so
Format() won't be effective.

One way:

With OutputSheet.Cells(OutputRowCounter - NumTrans - 2, 5)
.Value = Input1Sheet.Cells(2, 4).Value
.NumberFormat = "yyyy/mm/dd"
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top