使用 VBA 将“Wed Dec 02 24:00:00 GMT 2020”转换为 02/12/2020

时间:2021-01-18 10:44:11

标签: excel vba date

我想使用 VBA 将“Wed Dec 02 24:00:00 GMT 2020”转换为“02/12/2020”。

我创建了一个自定义函数。

Function Get_date(CellRef As String)
    Dim Year_num As Integer, Month_name As String, Month_num As Integer, Date_num As Integer'''
    Year_num = Right(CellRef, 4)
    Month_name = Mid(CellRef, 5, 3)
    Month_num = Month(DateValue(Month_name&("1")))
    Date_num = Mid(CellRef, 9, 2)
    
    Get_date = DateSerial(Year_num, Month_num, Date_num)
    
End Function

1 个答案:

答案 0 :(得分:0)

这会起作用:

Get-date = CDate(Right(CellRef, 4) & Mid(CellRef, 4, 7))