|
REPLACE
REPLACE replaces part of a text string, based on the number of characters you specify, with a different text string.
Syntax
REPLACE(old_text,start_num,num_chars,new_text)
Old_text is text in which you want to replace some characters.
Start_num is the position of the character in old_text that you want to replace with new_text.
Num_chars is the number of characters in old_text that you want REPLACE to replace with new_text.
New_text is the text that will replace characters in old_text.
Example
The example may be easier to understand if you copy it to a blank spreadsheet.
- Create a blank spreadsheet.
- Select the example in the Help topic.
![]()
Selecting an example from Help
- Press CTRL+C.
- In the spreadsheet, select cell A1, and press CTRL+V.
- To switch between viewing the formula that returns the result and the result in the cell, select the cell and press F2 and then ENTER, or click Commands and Options on the spreadsheet toolbar, click the Formula tab, and look in the Formula in active cell (active cell) box.
Data | |
---|---|
abcdefghijk | |
2009 | |
123456 | |
Formula | Description (Result) |
=REPLACE(A2,6,5,"*") | Replaces five characters, starting with the sixth character (abcde*k) |
=REPLACE(A3,3,2,"10") | Replaces the last two digits of 2009 with 10 (2010) |
=REPLACE(A4,1,3,"@") | Replaces the first three characters with @ (@456) |