Replaces part of a text string with a different text string.
REPLACE(originaltext, startposition, length, newtext)
in originaltext, removes length characters beginning at character startposition, replaces them with newtext, and returns the result.
startposition and length must be 1 or more.
REPLACE("mouse", 2, 3, "ic")
returns mice. Beginning at character position 2, 3 characters (ous) are removed and replaced by ic.
Correcting a Product Code Format
Imagine you have a list of product codes in your inventory, but there's a formatting issue. All the codes should start with "PROD-", but due to a data entry error, some were entered with "PDC-". You need to quickly and automatically correct all the "PDC-" prefixes to "PROD-".
Table:
Product Code (Original) | Desired Product Code | Corrected Product Code | ||
|---|---|---|---|---|
A | B | C | ||
1 | PDC-A123-456 | PROD-A123-456 | PROD-A123-456 | |
2 | PROD-B987-654 | PROD-B987-654 | PROD-B987-654 | |
3 | PDC-C321-789 | PROD-C321-789 | PROD-C321-789 | |
4 | PROD-D654-321 | PROD-D654-321 | PROD-D654-321 | |
5 | PDC-E987-123 | PROD-E987-123 | PROD-E987-123 |
The Formula in Cell B2:
You would use the following formula in the "Corrected Product Code" column. This formula first checks if the original code needs to be changed, and only then applies the REPLACE function.
IF(LEFT(A2,3)="PDC", REPLACE(A2, 1, 3, "PROD"), A2)
Explanation of the Formula:
This is a classic IF statement with three parts: IF(logical_test, value_if_true, value_if_false).
PRODUCT & FEATURES
RESOURCES
Terms | Privacy | Spam Policy
© 2026 Zapof