Replace() Function



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

Syntax

The syntax for the REPLACE function in Microsoft Excel is:

REPLACE( old_text, start_num, num_chars, new_text )

Parameters or Arguments

old_text

The original string value.

start_num

The position in old_text to begin replacing characters.

num_chars

The number of characters to replace in old_text.

new_text

The replacement set of characters.

Replace Function Examples

Column B of the following spreadsheet shows two examples of the Excel Replace Function.

Formulas:


A
B
1
test string
=REPLACE( A1, 7, 3, "X" )
2
second test string
=REPLACE( A2, 8, 4, "XXX" )

Results:


A
B
1
test string
test sXng
2
second test string
second XXX string

Common Error

You get an error from the Excel Replace function if
-          The supplied start_num argument is negative or is a non-numeric value
or
-          The supplied num_chars argument is negative or is non-numeric.

The Excel Replace function is designed for use with text strings and returns a text string. Therefore, if you attempt to use the replace function with a date, time or a number, you may get unexpected results.

Reference:



No comments:

Post a Comment

OR Function