REPLACE Function

Master the REPLACE function to replace text by position in Excel and Google Sheets. Learn syntax, examples, error solutions, and text techniques.

ExcelExcel
Google SheetsGoogle Sheets
text
intermediate
Syntax Preview
ExcelExcelGoogle SheetsGoogle Sheets
=REPLACE(old_text, start_num, num_chars, new_text)
Quick Answer
Comprehensive Explanation
Syntax and Parameters
How to Use REPLACE - Step by Step

Practical Examples

Update Year in Product Codes

Change the year portion of standardized product codes from 2023 to 2024

Result: PRD-2024-ABC-001

Format Phone Numbers

Convert 10-digit phone numbers to standard (XXX) XXX-XXXX format

Result: (555) 123-4567

Mask Credit Card Numbers

Replace middle digits with asterisks for security

Result: 4532********7890

Insert Department Codes

Add department prefix to existing employee IDs

Result: HR-EMP001

Fix Date Format Issues

Convert MM/DD/YYYY to DD-MM-YYYY format

Result: 15-09-2024

Dynamic SKU Updates with Cell References

Replace SKU components using values from other cells

Result: PROD-2024-GOLD-XL

Remove Characters with Empty String

Delete specific characters from postal codes

Result: K1A0B1

Common Errors and Solutions

#VALUE!

REPLACE returns #VALUE! error

Cause:

One or more arguments are non-numeric when numbers are expected, or start_num is less than 1

Solution:

1. Verify start_num is a positive number (use ABS or MAX functions if needed) 2. Check that num_chars is non-negative 3. Ensure numeric parameters aren't text (use VALUE function to convert) 4. Confirm cell references point to correct data types

Prevention:

Always validate numeric inputs with ISNUMBER before using in REPLACE

Frequency: 35%

Example:

Unexpected Results

Formula works but gives wrong output

Cause:

Incorrect position counting - remember Excel counts from 1, not 0; or hidden characters in the text

Solution:

1. Use LEN to verify text length 2. Use MID to test what character is at each position 3. Check for leading/trailing spaces with TRIM 4. Look for non-printing characters with CLEAN 5. Test with simple examples first

Prevention:

Create a helper column showing character positions for complex replacements

Frequency: 40%

Example:

#NAME?

Excel doesn't recognize REPLACE function

Cause:

Typo in function name, missing quotes around text arguments, or using wrong regional formula separator

Solution:

1. Check spelling - it's REPLACE not REPLAC or REPLACE 2. Ensure text strings are in quotes 3. Use correct argument separator (, or ; based on regional settings) 4. Verify the function is available in your Excel version

Prevention:

Use Formula AutoComplete to ensure correct spelling and syntax

Frequency: 15%

Example:

Position Beyond Text Length

Start position is greater than text length

Cause:

The start_num parameter exceeds the length of the text string

Solution:

1. Use LEN to check text length first 2. Add IF condition to handle this case 3. Consider if you meant to append instead 4. Use MIN function to cap position at text length

Prevention:

Always validate position against text length before replacement

Frequency: 10%

Example:

Best Practices and Advanced Techniques

Use FIND or SEARCH to locate text positions dynamically, then feed those positions to REPLACE. This creates powerful pattern-based replacements without hardcoding positions.

Chain multiple REPLACE functions to make several replacements in one formula. Work from right to left to avoid position shifts, or use LET function in Excel 365 to store intermediate results.

REPLACE is position-based while SUBSTITUTE is text-based. Use REPLACE when you know WHERE to change text, use SUBSTITUTE when you know WHAT text to change. Combining both can solve complex text challenges.

Wrap REPLACE in IFERROR or use IF statements to handle cases where positions might be invalid or text might be empty. This prevents errors in production spreadsheets.

REPLACE can extract specific portions of text by replacing everything else with empty strings. This provides a formula-based alternative to Text-to-Columns for dynamic data extraction.

REPLACE is very efficient even with thousands of rows. For best performance, avoid volatile functions in your position calculations and consider using helper columns for complex position logic.

REPLACE vs Similar Functions
Frequently Asked Questions

Need Help with REPLACE Function?

Stop struggling with formula syntax. Use AskFormulas to generate validated formulas instantly with our AI-powered tool.

Example Excel formula:

Related Formulas

LEFT Function in Excel

Extract text from the beginning of strings with the LEFT function. Learn syntax, examples, and error solutions for Excel and Google Sheets.

beginner
text
ExcelExcel
Google SheetsSheets
Validated
MID Function

Master the MID function to extract text from any position. Learn syntax, examples, and solutions to common errors for precise text manipulation.

beginner
text
ExcelExcel
Google SheetsSheets
Validated
RIGHT - Excel & Sheets

Master the RIGHT function to extract characters from text end. Learn syntax, examples, and solutions for text manipulation in Excel and Google Sheets.

beginner
text
ExcelExcel
Google SheetsSheets
Validated
SUBSTITUTE Function

Master the SUBSTITUTE function to replace text in Excel and Google Sheets. Learn syntax, examples, error handling, and advanced text techniques.

intermediate
text
ExcelExcel
Google SheetsSheets
Validated