简体   繁体   English

将带有星期几缩写的文本日期转换为excel日期格式

[英]convert text date with day of week abbreviation to excel date format

I am trying to figure out how to remove the abbreviation for the day of the week from cells and then convert the text string date to an excel date format. 我试图弄清楚如何从单元格中删除星期几的缩写,然后将文本字符串日期转换为excel日期格式。 This is an example of the format which will always be the same. 这是格式始终不变的示例。

Thu 8/24/2017 2017年8月24日星期四

If I manually delete the day of week letters and then use the text to columns function in excel, it works fine converting into a date format. 如果我手动删除星期几字母,然后在excel中使用“文本转栏”功能,则可以很好地转换为日期格式。 The text to columns function does not work on cells containing the day abbreviation. 文字转栏功能不适用于包含日期缩写的单元格。

I am looking for the quickest method (VBA or formula) to remove these abbreviations from multiple columns. 我正在寻找最快的方法(VBA或公式)从多个列中删除这些缩写。 Find and replace with "" will be an option, but I am hoping for something less manual and time consuming, as I will be working with this spreadsheet regularly. 查找和替换为“”是一个选项,但是我希望减少手动和时间,因为我将定期使用此电子表格。 Thank you in advance for your help! 预先感谢您的帮助!

Use: 采用:

=--MID(A1,FIND(" ",A1)+1,LEN(A1))

Then format it any way you want 然后以任何方式格式化

在此处输入图片说明

You can do this in-place by ignoring the first field in Text-to-Columns. 您可以通过忽略“文本到列”中的第一个字段来就地执行此操作。

With Worksheets("sheet3")
    With .Range(.Cells(2, "A"), .Cells(.Rows.Count, "A").End(xlUp))
        .TextToColumns Destination:=.Cells(1), DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
            ConsecutiveDelimiter:=True, Tab:=False, Semicolon:=False, Comma:=False, Space:=True, Other:=False, _
            FieldInfo:=Array(Array(1, 9), Array(2, 3))
    End With
End With

This will transform your text into an excel date format: 这会将您的文本转换为excel日期格式:

=DATEVALUE(MID(B2,4,10))

"Thu 8/24/2017" will become "42971" under a general format, "8/24/2017" under a short date format or "Thursday, August 24, 2017" under a long date format. 一般格式的“星期四2017年8月24日”将变为“ 42971”,短日期格式将变为“ 8/24/2017”,长日期格式将变为“ 2017年8月24日,星期四”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM