This Excel tutorial explains how to use the Excel REPLACE function (in VBA) with syntax and examples.
The Microsoft Excel REPLACE function replaces a sequence of characters in a string with another set of characters. Please note that the worksheet version of the REPLACE function has different syntax.
The syntax for the REPLACE function in Microsoft Excel is:
Replace ( string1, find, replacement, [start, [count, [compare]]] )
Optional. This can be one of the following values:
The REPLACE function can be used in the following versions of Microsoft Excel:
The REPLACE function can be used in Microsoft Excel as the following type of function:
The REPLACE function can be used in VBA code in Microsoft Excel.
Let's look at some Excel REPLACE function examples and explore how to use the REPLACE function in Excel VBA code:
Replace("alphabet", "bet", "hydro") Result: "alphahydro" Replace ("alphabet", "a", "e") Result: "elphebet" Replace("alphabet", "a", "e", 2) Result: "lphebet" Replace("alphabet", "a", "e", 1, 1) Result: "elphabet"
Dim LResult As String LResult = Replace("alphabet", "a", "e")
In this example, the variable called LResult would now contain the value "elphebet".
(scroll to see more)