PDA

View Full Version : Format a cell before writing in it



circaa
06-09-2006, 11:02 AM
Hi

What I really want to do is format the cell to display a date with this pattern "yyyy-mm-dd"

thanks

mvidas
06-09-2006, 12:05 PM
Hi circaa, Range("A1").NumberFormat = "yyyy-mm-dd"
Range("A1").Value = Date
'or
With Range("A1")
.NumberFormat = "yyyy-mm-dd"
.Value = Date
End WithMatt

mdmackillop
06-09-2006, 05:06 PM
Hi Circaa,
Similar code to Matt's. As I don't know where you are, regional settings could give erroneous results; maybe a way forward though!
Regards
MD


Private Sub Worksheet_Change(ByVal Target As Range)
If IsDate(Target) Then
With Target
.NumberFormat = "yyyy-mm-dd"
.Value = DateValue(Target)
End With
End If
End Sub