다음을 통해 공유


WorksheetFunction.Replace Method (Excel)

Replaces part of a text string, based on the number of characters you specify, with a different text string.

Syntax

.Replace(Arg1, Arg2, Arg3, Arg4)

A variable that represents a WorksheetFunction object.

Parameters

Name

Required/Optional

Data Type

Description

Arg1

필수

String

Text in which you want to replace some characters.

Arg2

필수

Double

The position of the character in Arg1 that you want to replace with Arg4.

Arg3

필수

Double

The number of characters in Arg1 that you want the Replace method to replace with Arg4.

Arg4

필수

String

Text that will replace characters in Arg1.

Return Value

A String value that represents the new string, after replacement.

Example

This example replaces abcdef with ac-ef and notifies the user during this process.

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

참고 항목

개념

WorksheetFunction Object

WorksheetFunction Object Members