【发布时间】:2014-05-06 17:22:03
【问题描述】:
我创建这个子的目的是采用默认的美国日期约定,将其更改为英国格式“yyyy-mm-dd”,然后转换为字符串。我想在转换为字符串之前更改格式,因为它更容易用于我的目的。但是,尽管单元格格式已更改,但该字符串似乎仍保留为原始美国格式。我该如何解决这个问题,它这样做的原因是什么?
Sub Changedate()
Sheet1.Cells(1, 3).Select
Selection.NumberFormat = "yyyy-mm-dd;@"
Sheet1.Cells(1, 4).Select
Selection.NumberFormat = "yyyy-mm-dd;@"
Dim firstDate As String
Dim secondDate As String
firstDate = Str(Sheet1.Cells(1, 3).Value)
secondDate = Str(Sheet1.Cells(1, 4).Value)
MsgBox firstDate
Sheet1.Cells(1, 3).Select
Selection.NumberFormat = "m/d/yyyy"
Sheet1.Cells(1, 4).Select
Selection.NumberFormat = "m/d/yyyy"
End Sub
【问题讨论】:
-
您在单元格中实际看到的典型值是什么......“格式”值?
标签: string date excel casting vba