Date Format

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

What is wrong? with the line below

ws.Cells(freerownum, 7).Value = Format(Tb1, "dd/mm/yy")

On the sheet it converts it to US Format ("mm/dd/yy")

Why?
 
In VBA if a string can be interpreted as a US formatted date, it will be.
Try this

With ws.Cells(freerownum, 7)
.Value = DateValue(Tb1)
.NumberFormat = "dd/mm/yy"
End With
 
Perhaps its the variables. The following:

Sub hazel()
Set ws = Sheets("sheet1")
freerownum = 1
Tb1 = Now
ws.Cells(freerownum, 7).Value = Format(Tb1, "dd/mm/yy")
End Sub

puts:
9/8/2007
in the cell - clearly in day/month/year format.
 
TB1 is a string, not a date.

Plus, I would check on what is so clear.
 
Hi

Everybody's help much appreciated, I have used and tried Tom's solution and
it works perfectly even on the other 3 textboxes that are used to input dates
on the sheet - hopefully because I save all the snippets of code etc that
help me I might never again need anything about UK / US date formatting.
 

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

Back
Top