excel用不同的angular色位置replace多个实例

我有一个从大约6500行的sql数据库的数据集与一列包含多个值的字段。

Cell A1 3.00GGG1.00DDD2.00EEE1.00DEF5.00TTT Cell A2 10.00ABC1.00DDD2.00EEE1.00DEF 

.00是string中唯一一致的系列字符
我需要引入一个“,”,以便能够使用文本到列工具将值分成不同的列
并发症是十进制左边的数字可以变化,可以是10或更大,所以逗号的位置可以是小数点左边的1或2个位置

所以我需要一个实现

 Cell A1 ,3.00GGG,1.00DDD,2.00EEE,1.00DEF,5.00TTT Cell A2 ,10.00ABC,1.00DDD,2.00EEE,1.00DEF 

最终通过使用文字来实现

 3.00GGG 1.00DDD 2.00EEE 1.00DEF 5.00TTT 10.00ABC 1.00DDD 2.00EEE 1.00DEF 

有没有人有任何想法如何通过公式或macros来实现这一点?

谢谢!

我从来没有想过我会这样说,但对我来说,它实际上使用Word。

将行复制到Word文档。 打开查找/replace(CTRL + H) ,点击More>>打开高级菜单并勾选Use wildcards

然后input查找内容([0-9]{1,2}.)和replace为,\1 。 点击全部replace,并将所有内容复制回Excel表单。

我使用RegEx为你写了一些东西。 它确实有漏洞,试试这个,如果不行的话,我们会钻空子的。

 call findMatch("3.00GGG1.00DDD2.00EEE1.00DEF5.00TTT ","[A-Za-z]\d") Function findMatch(strValue, strPattern) Dim objRegEx Dim objPosition Dim strPosition strNewVal = strValue 'find out how many different strings will be there countOfStrings = len(strNewVal) - len(replace(strNewVal, ".", "")) strCompiledString = "" 'Create regular expression Set objRegEx = CreateObject("VBScript.RegExp") objRegEx.Pattern = strPattern 'loop to break the string up and tie it with comma for i= 1 to countOfStrings if not objRegEx.Test(strValue) then 'if condition to check whether or not there are any matches strCompiledString = strCompiledString & "," & strValue exit for end if Set objPosition = objRegEx.Execute(strValue) strPosition = objPosition(0).FirstIndex findMatch= strPosition 'based on match index, add the left part of the string to the variable strCompiledString if(strCompiledString="") then strCompiledString = mid(strValue,1,strPosition+1) else strCompiledString = strCompiledString & "," & mid(strValue,1,strPosition+1) end if 'remove the already processed substring from the main string strValue = mid(strValue,strPosition+2) next 'now we have it msgbox("BOOOOM : " & strCompiledString) End Function 

我修改了一个UDF,我为了从string中获得第n个数字而得到第n个数字加上字母:

 Function GetNthNumber(s As String, n As Integer) As String Dim c, testNumber, number As String s = s & "0" Dim i, j, count As Integer Dim inNumber As Boolean inNumber = False ' Loop through each character of string For i = 1 To Len(s) c = Mid(s, i, 1) ' Part of a number - append new character or finish number If inNumber Then If Not (IsNumeric(number & c)) Then inNumber = False End If number = number & c Else ' Not part of a number - start new number or do nothing If IsNumeric(c) Then If count = n Or i = Len(s) Then Exit For inNumber = True number = c count = count + 1 Else number = number + c End If End If Next i 'Return nth number or #Value error If count >= n Then GetNthNumber = number Else GetNthNumber = CVErr(xlErrValue) End If End Function 

要使用它,请调用函数来获取第一个数字,并将其拖过去,直到出错

 =IFERROR(GetNthNumber($A1,COLUMN(A:A)),"") 

在这里输入图像描述