如何使用 MS Excel 分隔符在有数字的地方拆分单词

How to split a word whereever there's a number using MS Excel Delimiter

所以我有一个组合列表,如下所述,我需要将其拆分为一个字母和一个数字。

我希望使用 MS 将其拆分如下 Excel; Text to Columns Delimit 函数或任何其他有效函数-

我尝试使用固定宽度,如果字母字符后有 2 位或更多数字值,则该方法不起作用。有没有办法做到这一点,因为我必须对 13000 种组合重复此操作?

在找到模式的地方插入一个分隔符,然后将修改后的字符串拆分成新的列。

Option Explicit

Sub makeSplit()

    Dim i As Long, j As Long, str As String, arr As Variant

    'set the worksheet
    With Worksheets("sheet5")

        'step throughj the cells in column A
        For i = .Cells(.Rows.Count, "A").End(xlUp).Row To 2 Step -1

            'put the cell value into a variable
            str = .Cells(i, "A").Value2

            'step through the characters in the sting backwards
            For j = Len(str) - 1 To 3 Step -1

                'is the current character alphabetic and the previous character a digit?
                If Not IsNumeric(Mid(str, j, 1)) And IsNumeric(Mid(str, j - 1, 1)) Then

                    'insert a space
                    str = Left(str, j - 1) & Space(1) & Mid(str, j)

                End If

            Next j

            'split the string using the space as delimiter
            .Cells(i, "A").Resize(1, UBound(Split(str, Space(1))) + 1) = Split(str, Space(1))

        Next i

    End With

End Sub

由于文本是常量,创建一个 header 行常量,并将您的值从 A1 开始,将此公式放入 B2 并向下复制:

=MID($A2,FIND(B,$A2),IF(ISNUMBER(--MID($A2,FIND(B,$A2)+2,1)),3,2))

我找到了一种方法,但会占用大量资源。

首先将所有字符串放在 sheet 列中,并确保该列的列可用。

然后新建一个空的第一行,然后输入字母 R、C、P、D、O、S,因为你说过它们总是按这个顺序排列的。这些是公式所需的识别字母。

现在在每个字母的下面,每个字符串的右边,输入公式

=C&MAX(IFERROR(VALUE(MID($A2,SEARCH(C,$A2)+1,2)),0),VALUE(MID($A2,SEARCH(C,$A2)+1,1)),0)

只有当数字不再是 2 位数字时才有效,如果是 3 位数字,则为

=C&MAX(IFERROR(VALUE(MID($A2,SEARCH(C,$A2)+1,3)),0),IFERROR(VALUE(MID($A2,SEARCH(C,$A2)+1,2)),0),VALUE(MID($A2,SEARCH(C,$A2)+1,1)),0)

对于四个,继续添加 IFERROR() 和 )),2) )),3) 像上面一样增加。

计算完所有公式后,如果要删除公式,可以复制并粘贴为值。

示例sheet(荷兰语Excel):