← All how-to recipes

How to use LEFT, MID, and RIGHT

✓ Verified in LibreOffice 25.8.7.3 ✓ Verified in Google Sheets (2026-08-30)

Pull characters from the start, middle, or end of a text value — extract codes, initials, or fixed-width fields.

The formula

AppFormulaNotes
Excel (desktop)=MID(A2,4,3)LEFT(text,n) from the start; RIGHT(text,n) from the end; MID(text,start,n) from a position.
Google Sheets=MID(A2,4,3)Identical.
LibreOffice Calc=MID(A2,4,3)Identical.

How it works

The three text-slicing functions work by position: LEFT(A2,3) takes the first 3 characters ("ABC"), RIGHT(A2,3) takes the last 3 ("XYZ"), and MID(A2,4,3) starts at character 4 and takes 3 ("123"). They count every character including spaces. The power move is combining them with FIND to slice at a delimiter rather than a fixed position — LEFT(A2,FIND("-",A2)-1) grabs everything before the first dash. On modern versions, TEXTBEFORE/TEXTAFTER read more clearly for delimiter-based extraction, but LEFT/MID/RIGHT are universal and exactly right for fixed-width data like part codes and account numbers.

Verified, not just documented

We ran =MID(A2,4,3) in LibreOffice 25.8.7.3 (headless, with forced recalculation) and it returned 123 — exactly the expected result. We then ran the same formulas in Google Sheets, executed 2026-08-30: a formula-only workbook goes into Google Drive, which converts it to a Sheet and recalculates every formula with Google’s own engine, and comes back out as .xlsx carrying the values Google computed. It returned 123 for the worked example, the same value LibreOffice produced. Both engines’ numbers on this page are executed results. The Excel formula follows Microsoft’s official documented syntax — we do not run desktop Excel.

Functions used

MID — see full Excel, Google Sheets & LibreOffice compatibility for each.

Related recipes

Related comparisons