Date Format

H

Hazel

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?
 
T

Tom Ogilvy

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
 
G

Gary''s Student

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.
 
H

Hazel

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

Top