Contact

REPLACE Function in Apple Numbers: Syntax, Examples and Troubleshooting

Text Intermediate Apple Numbers

Modify fixed-width segments of text identifiers with position-based Apple Numbers formulas.

Verification status: See the evidence and test scope described in this guide. How formula examples are checked

=REPLACE("CA-2048-R1",4,4,"XXXX") produces CA-XXXX-R1. Apple Numbers REPLACE changes a segment at a character position. Use SUBSTITUTE when the target is matching text rather than a known position.

Availability and version history

  • Introduced: The original introduction release and date are not established by the checked official sources.
  • Availability: Currently documented in Apple’s Formulas and Functions Help 15.4 edition; no final supported-version endpoint is established.
  • Scope: Shared iWork function documentation, not a Numbers application build number. Individual historical and client-specific endpoints remain unverified.
  • Checked: October 14, 2026, against the official REPLACE entry. Examples were independently calculated; no native Numbers execution was performed.

Syntax and required arguments

REPLACE(source-string, start-pos, replace-length, new-string)

All four arguments are required. Apple permits any value for the source and replacement. The start is one-based and must be at least 1; the number of characters to replace must also be at least 1. The new text may be shorter or longer than the removed segment. Do not import a zero-length insertion formula from another product into this documented contract.

Apple also states two useful boundaries: a start beyond the source’s length appends the replacement; a start of 1 with a replacement length at least as long as the source replaces the whole source. Its direct examples include both text and a numeric source, with string results.

Mask the original four fixed-width codes

Create Code Cleanup, with six columns and eight rows. Put Code, Masked, Source length, Result length, Same length and Changed separator in A1:F1. Format A2:A5 as Text before entering:

Row A: Code Expected B: Masked
2 CA-2048-R1 CA-XXXX-R1
3 US-7312-R2 US-XXXX-R2
4 UK-0097-R3 UK-XXXX-R3
5 CA-6005-R1 CA-XXXX-R1

Enter the following formulas, then fill B2:F2 through row 5:

B2: =REPLACE(A2,4,4,"XXXX")
C2: =LEN(A2)
D2: =LEN(B2)
E2: =C2=D2
F2: =REPLACE(A2,3,1,"_")

C and D are 10 on all four rows; E is TRUE. F contains CA_2048-R1, US_7312-R2, UK_0097-R3 and CA_6005-R1. LEN confirms the equal lengths, but equal length alone does not prove that the correct segment was changed.

Duplicate the table as ChangedCode. Change only A2 to CA-9876-R1. B2 still reads CA-XXXX-R1, while F2 becomes CA_9876-R1. Masking deliberately discards the four middle digits, so two different original codes can have the same masked result. Preserve the source if it is needed for reconciliation.

Replacement length and output length are different

On ReplacementCases, create six columns and eight rows. Enter the complete formulas separately:

Cell Formula Expected text
A2 =REPLACE("CA-2048-R1",4,4,"X") CA-X-R1
A3 =REPLACE("CA-2048-R1",4,4,"REDACTED") CA-REDACTED-R1
A4 =REPLACE("ABC",5,1,"Z") ABCZ
A5 =REPLACE("ABC",1,3,"Z") Z
A6 =REPLACE("ABC",1,5,"Z") Z
A7 =REPLACE(6060606,2,2,30303) 6303030606

B2 =LEN(A2) filled through B7 gives 7, 14, 4, 1, 1, 10. C2 =ISTEXT(A2) filled through C7 gives TRUE throughout, including the numeric-input example. The removal count is not a requested final width.

Advanced: locate the field before replacing it

Create VariableCodes, with eight columns and six rows. Enter CA-2048-R1, CAN-2048-R1 and CAN-97-R1 in A2:A4. Every example has two hyphens and a nonempty middle field.

Put these formulas in row 2 and fill B2:H2 through row 4:

B2: =FIND("-",A2)
C2: =FIND("-",A2,B2+1)
D2: =C2-B2-1
E2: =REPLACE(A2,B2+1,4,"XXXX")
F2: =REPLACE(A2,B2+1,D2,"XXXX")
G2: =MID(A2,B2+1,D2)
H2: =D2=4
Row B C D E: fixed count F: measured count G H
2 3 8 4 CA-XXXX-R1 CA-XXXX-R1 2048 TRUE
3 4 9 4 CAN-XXXX-R1 CAN-XXXX-R1 2048 TRUE
4 4 7 2 CAN-XXXX1 CAN-XXXX-R1 97 FALSE

FIND handles the varying prefix; the difference between the two found positions handles the field width. MID exposes exactly what F removes. E4 shows the danger of assuming four characters when the field contains only two: it also removes the following hyphen and R.

This is an extraction-and-replacement pattern for the stated shape, not full identifier validation. Missing delimiters or an empty field need a separate policy before calling the functions; Apple requires a positive replacement length. Nor does the width check establish that the middle field contains only digits.

Formula entry and practical limits

Examples use commas between arguments, ordinary straight quotation marks around literals, one header row and no header columns. If your decimal separator is a comma, Numbers uses semicolons between arguments. Keep output columns separate from the original data, and select source cells in the formula editor if table-qualified references are needed.

The short function entry does not establish every imported type, error-propagation rule or exact error message. These explicit examples do not certify complex Unicode segmentation or cross-client workbook conversion. Diagnose a mismatch with a small original input before changing a whole column.