这里有一个解决方案:
我编写了一个函数,它用 strReplace 替换所有出现的字符串 strFind,但前提是 strFind 出现在括号内。因此,您可以将所有“,”字符替换为其他字符(例如“*”),然后将 Excel 的文本运行到列,然后再次将“*”替换为“,”。
Function replace_paren(strSource As String, strFind As String, strReplace As String) As String
' Within strString, replaces any occurrence of strFind with strReplace *IF* strFind occurs within parentheses '
Dim intOpenParenIndex As Integer
Dim intCloseParenIndex As Integer
Do
intOpenParenIndex = InStr(intCloseParenIndex + 1, strSource, "(")
intCloseParenIndex = InStr(intOpenParenIndex + 1, strSource, ")")
If intOpenParenIndex = 0 Then
Exit Do
End If
Mid(strSource, intOpenParenIndex, intCloseParenIndex - intOpenParenIndex) = Replace(Mid(strSource, intOpenParenIndex, intCloseParenIndex - intOpenParenIndex), strFind, strReplace)
Loop
replace_paren = strSource
End Function
所以步骤是:
1) 将此宏复制到 Excel 工作簿中的模块中
2)假设您的字符串在A列中。在B列中,设置函数以替换逗号
=replace_paren(A1,",","*")
3) 将公式向下填充列
4) 将该列复制并粘贴为值
5) 使用 Excel 的文本到列来解析列,使用“,”作为分隔符
6) 再次使用replace_paren 将所有出现的“*”替换为“,”