MID
Returns a substring starting at a 1-based position.
The Formualizer engine in this repository at 0.15.0 plus unreleased changes computes the example results. Known differences from Excel are listed on this page.
Syntax
=MID(text, start_num, num_chars)
Arguments
| Argument | Type | Required | Default |
|---|---|---|---|
text | any | Required | — |
start_num | any | Required | — |
num_chars | any | Required | — |
Return type
Can return text.
Remarks
- If start is beyond the end of the text, returns an empty string.
- Non-text inputs are coerced to text.
Error cases
start_numis 1-based; values below1return#VALUE!.num_charsmust be non-negative; negatives return#VALUE!.
Examples
Extract the year from the middle of a label by position.
Formula =MID("East-2024",6,4)
Expected result 2024
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
A requested count beyond the remaining text reaches only the end.
Formula =MID("East-2024",6,20)
Expected result 2024
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
A zero count produces an empty substring.
Formula =MID("East-2024",6,0)
Expected result ""
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
A start position of zero is invalid.
Formula =MID("East-2024",0,4)
Expected result #VALUE!
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Extract middle segment
Formula =MID("spreadsheet", 3, 5)
Expected result reads
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Start past end returns empty
Formula =MID("abc", 10, 2)
Expected result ""
Try this formula
This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.
Related functions
FAQ
How does MID handle out-of-range start positions?
If start_num is beyond the text length, MID returns an empty string.