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




=REPLACE(old_text, start_num, num_chars, new_text)
Practical Examples
Update Year in Product Codes
Change the year portion of standardized product codes from 2023 to 2024
Format Phone Numbers
Convert 10-digit phone numbers to standard (XXX) XXX-XXXX format
Mask Credit Card Numbers
Replace middle digits with asterisks for security
Insert Department Codes
Add department prefix to existing employee IDs
Fix Date Format Issues
Convert MM/DD/YYYY to DD-MM-YYYY format
Dynamic SKU Updates with Cell References
Replace SKU components using values from other cells
Remove Characters with Empty String
Delete specific characters from postal codes
Common Errors and Solutions
REPLACE returns #VALUE! error
One or more arguments are non-numeric when numbers are expected, or start_num is less than 1
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
Always validate numeric inputs with ISNUMBER before using in REPLACE
Example:
Formula works but gives wrong output
Incorrect position counting - remember Excel counts from 1, not 0; or hidden characters in the text
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
Create a helper column showing character positions for complex replacements
Example:
Excel doesn't recognize REPLACE function
Typo in function name, missing quotes around text arguments, or using wrong regional formula separator
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
Use Formula AutoComplete to ensure correct spelling and syntax
Example:
Start position is greater than text length
The start_num parameter exceeds the length of the text string
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
Always validate position against text length before replacement
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.
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
Extract text from the beginning of strings with the LEFT function. Learn syntax, examples, and error solutions for Excel and Google Sheets.


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


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


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

