我有一张有这么多行的表。它的结构如下图:
如您所见,我在 A 列中的名称之间有“或”、“与”。我如何将这些列分成两部分?在这种情况下,第一列将有 David、Tylor、Fred、Jessi、Roland,第二列有 Peter、Mark、Alfered、Hovard 和 DAvid。
注意:请注意第 2 行和第 5 行。在这些行中,我有 2 个“或”或两个“与”。
编辑:我更喜欢在 Excel 中执行此操作
我试过的
作为一种可能的解决方案,我在 vba 中有这个功能。
Function udfRegEx(CellLocation As Range, RegPattern As String)
Dim RegEx As Object, RegMatchCollection As Object, RegMatch As Object
Dim OutPutStr As String
Dim i As Integer
i = ActiveWorkbook.Worksheets(ActiveWorksheet.Name).UsedRange.rows.Count
Set RegEx = CreateObject("vbscript.regexp")
With RegEx
.Global = True
.Pattern = RegPattern
End With
OutPutStr = ""
Set RegMatchCollection = RegEx.Execute(CellLocation.Value)
For Each RegMatch In RegMatchCollection
OutPutStr = OutPutStr & RegMatch
Next
udfRegEx = OutPutStr
Set RegMatchCollection = Nothing
Set RegEx = Nothing
Set Myrange = Nothing
End Function
此函数使用正则表达式。但我不知道如何使用它。