解決策は次のとおりです。
文字列strFindのすべての出現箇所をstrReplaceで置き換える関数を作成しましたが、これは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を使用して、出現するすべての「*」を「、」に置き換えます。