【发布时间】:2014-04-24 19:18:37
【问题描述】:
我目前有多个格式如下的记录:
24th April 2014
但是,我希望它的格式如下:
24/04/2014 or 24/04/14 (either way is fine, does not really matter)
顺便说一句,我正在使用 excel 2013。
感谢您的任何反馈。
【问题讨论】:
标签: excel
我目前有多个格式如下的记录:
24th April 2014
但是,我希望它的格式如下:
24/04/2014 or 24/04/14 (either way is fine, does not really matter)
顺便说一句,我正在使用 excel 2013。
感谢您的任何反馈。
【问题讨论】:
标签: excel
如果您能够从日期中删除“th”,Excel 将能够自动对其进行格式化。如果你有很多数据,一个简单的 vba 脚本就可以了。
【讨论】:
选择要转换的单元格并运行宏ReDate
Sub ReDate()
Dim r As Range
For Each r In Selection
ary = Split(r.Value, " ")
r.Clear
r.Value = DateSerial(ary(2), Monthh(CStr(ary(1))), Numbrs(CStr(ary(0))))
Next r
End Sub
Public Function Monthh(s As String) As Long
Dim mnth(1 To 12) As String
mnth(1) = "January"
mnth(2) = "February"
mnth(3) = "March"
mnth(4) = "April"
mnth(5) = "May"
mnth(6) = "June"
mnth(7) = "July"
mnth(8) = "August"
mnth(9) = "September"
mnth(10) = "October"
mnth(11) = "November"
mnth(12) = "December"
Monthh = Application.WorksheetFunction.Match(s, mnth, 0)
End Function
Public Function Numbrs(sIn As String) As Long
Dim L As Long, v As String, i As Long
Dim CH As String
L = Len(sIn)
v = ""
For i = 1 To L
CH = Mid(sIn, i, 1)
If CH Like "[0-9]" Then
v = v & CH
End If
Next i
Numbrs = CLng(v)
End Function
【讨论】:
我认为 DATEVALUE 函数应该可以解决这个问题。
=DATEVALUE(LEFT(A1,FIND(" ",A1)-3)&RIGHT(A1,LEN(A1)-FIND(" ",A1)+1))
假设日期文本存储在 A 列中。我们知道主要问题是关于“st”或“nd”或“th”或“rd”的存在。如果它们不存在,Excel 可以自动识别该日期值。所以我尝试使用 text 函数创建带有“th”的日期文本:
LEFT(A1,FIND(" ",A1)-3)&RIGHT(A1,LEN(A1)-FIND(" ",A1)+1)
然后使用DATEVALUE函数将它们转换为日期值,我认为它已经完成了。
对吗?希望这能有所帮助!
【讨论】: