我的工作表有一个包含以下内容的文本字段:
2017年10月18日星期三,美国东部时间晚上9:30
我需要将其转换为日期格式。我不关心时间,我只需要看起来像这样:10/18/2017。
任何帮助都将不胜感激。
答案 0 :(得分:1)
解析字符串:
=--(LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",999)),2*999,999)),LEN(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",999)),2*999,999)))-3) & " " & TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",999)),999,999)) & " " & LEFT(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",999)),3*999,999)),LEN(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",999)),3*999,999)))-1))
然后根据需要进行格式化。
答案 1 :(得分:1)
如果您想将值转换为,请选择相关的单元格并运行此短宏:
Sub INeedADate()
Dim r As Range, d As Date, s As String, DQ As String
DQ = Chr(34)
For Each r In Selection
ary = Split(r.Text, " ")
s = DQ & ary(1) & " " & numpart(ary(2)) & ", " & Left(ary(3), 4) & DQ
r.Formula = "=DATEVALUE(" & s & ")"
r.NumberFormat = "mm/dd/yyyy"
Next r
End Sub
Public Function numpart(s) As String
Dim L As Long, i As Long
L = Len(s)
numpart = ""
For i = 1 To L
If IsNumeric(Mid(s, i, 1)) Then numpart = numpart & Mid(s, i, 1)
Next i
End Function
答案 2 :(得分:1)