如果我有一个包含以下内容的单元格:
Tuesday, April 16th 2009
Run Code Online (Sandbox Code Playgroud)
如何将该字符串转换为Excel识别的日期格式.我想我必须使用MID()和FIND()函数.
这是一个可以在VBA和用户定义函数中运行的函数
Function GetDate(InString As Range) As Date
Dim newDate As Date
Dim tmpDate As String
'Sample Date
'Tuesday, April 16th 2009
'Remove the Day of the Week.
tmpDate = Trim(Mid(InString, InStr(InString, ",") + 1))
'Get rid of "th"
tmpDate = Replace(tmpDate, "th ", " ")
'Get rid of "rd"
tmpDate = Replace(tmpDate, "rd ", " ")
'Get rid of "nd"
tmpDate = Replace(tmpDate, "nd ", " ")
'Get rid of "st"
tmpDate = Replace(tmpDate, "st ", " ")
'Convert string to date
newDate = DateValue(tmpDate)
GetDate = newDate
End Function
Run Code Online (Sandbox Code Playgroud)