删除单元格中的部分文本并保留其他文本

Jay*_*Jay 4 excel vba

`4/19/2020 6:00:00 PM - 这就是细胞内部的东西。我想删除“6:00:00 PM”部分,但我能找到的唯一功能是 .REPLACE 功能,它只是擦除整个单元格并将其变为空白。每个单元格都有不同的日期,所以我不能每次都用相同的日期替换它。

With Columns("E:E")
.Replace What:="?*:00:00 PM=", Replacement:="?*:00:00 PM "
.Replace What:="?*:00:00 PM", Replacement:=""
End With
With Columns("H:H")
.Replace What:="?*:00:00 PM=", Replacement:="?*:00:00 PM "
.Replace What:="?*:00:00 PM", Replacement:=""
End With
Run Code Online (Sandbox Code Playgroud)

Gar*_*ent 7

如果E列中的值是真实的日期/时间,则运行:

Sub dropTime()
    With Range("E:E").Cells
        .NumberFormat = "m/d/yyyy "
    End With
End Sub
Run Code Online (Sandbox Code Playgroud)

如果E列中的值是文本值,则运行:

Sub dropTime2()
    Dim rng As Range, r As Range, arr
    Set rng = Intersect(Range("E:E"), ActiveSheet.UsedRange)
    For Each r In rng
        arr = Split(r.Text, " ")
        If UBound(arr) = 2 Then
            r.Value = arr(0)
            r.NumberFormat = "m/d/yyyy "
        End If
    Next r
End Sub
Run Code Online (Sandbox Code Playgroud)