WorksheetFunction.Replace メソッド (Excel)

指定した文字数に基づいて、テキスト文字列の一部を別のテキスト文字列に置き換えます。

構文

Replace (Arg1Arg2Arg3Arg4)

: WorksheetFunction オブジェクトを表す変数。

パラメーター

名前 必須 / オプション データ型 説明
Arg1 必須 文字列型 (String) 置き換えを行う文字列を指定します。
Arg2 必須 Double Arg4 と置き換える Arg1 内の文字の位置を指定します。
Arg3 必須 Double Replace メソッドで Arg4 と置き換える Arg1 内の文字の数を指定します。
Arg4 必須 String Arg1 の一部と置き換える文字列を指定します。

戻り値

置換後の新しい文字列を表す String 値。

次の使用例は、abcdef を ac-ef に置き換え、その処理経過を表示します。

Sub UseReplace() 
 
 Dim strCurrent As String 
 Dim strReplaced As String 
 
 strCurrent = "abcdef" 
 
 ' Notify user and display current string. 
 MsgBox "The current string is: " & strCurrent 
 
 ' Replace "cd" with "-". 
 strReplaced = Application.WorksheetFunction.Replace _ 
 (Arg1:=strCurrent, Arg2:=3, _ 
 Arg3:=2, Arg4:="-") 
 
 ' Notify user and display replaced string. 
 MsgBox "The replaced string is: " & strReplaced 
 
End Sub

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。