【发布时间】:2019-10-29 02:58:11
【问题描述】:
我有一个 excel 文件,其中的单元格包含一些 cmets,例如:
txxxxx:2019 年 10 月 15 日上午 11:38:48 - 客户 ID:xxxxx ) 第一个联系人 - 文本仅发送到 Mob TN xxxxxxw/Ref &TN
Txxxxxx:10/18/2019 下午 1:34:12 - 打电话给BEST CBR xxxxxx,与先生交谈,他说他们一直很忙,还无法查看/讨论。主动向他发送我们的直接信息,他们将在网上查询和/或很快给我们打电话。
一条短信已成功发送到 xxxxxx 的 Gull Family
OK WITH FINAL CB 下周。
文本可以是任何可能包含多个日期时间字段的内容。 我正在尝试从每个单元格中提取所有此类日期出现并将它们放在不同的列中
我尝试使用=regExFind 和=regExExtract。例如:
=RegExFind($Cell,"\d{2}/\d{2}/\d{4}")
我也试过=Text($cell, dd/mm/yyyy)
但是,这两种方法都行不通。 excel中有没有办法进行正则表达式提取,如果有,如何实现? 如果没有,提取所有日期时间字段的最佳方法是什么?
更新: 这是我使用的代码:
Function RegexExtract(ByVal text As String, _
ByVal extract_what As String, _
Optional separator As String = ", ") As String
Dim allMatches As Object
Dim RE As Object
Set RE = CreateObject("vbscript.regexp")
Dim i As Long, j As Long
Dim result As String
RE.pattern = extract_what
RE.Global = True
Set allMatches = RE.Execute(text)
For i = 0 To allMatches.count - 1
For j = 0 To allMatches.Item(i).submatches.count - 1
result = result & (separator & allMatches.Item(i).submatches.Item(j))
Next
Next
If Len(result) <> 0 Then
result = Right$(result, Len(result) - Len(separator))
End If
RegexExtract = result
End Function
但没有输出。
【问题讨论】:
-
regExFind()和regExExtract()不是 EXCEL 内置函数。你能出示他们的代码吗? -
您使用的是什么版本的 Excel?您能否提供更多包含多个日期时间信息和预期结果的示例?如果可以的话,可以使用 excel 公式或幂查询来完成吗?
-
我添加了代码