Instant digital downloadExcel and Google SheetsSecure card checkout

Excel and Google Sheets how-to

Take the first, last or middle characters from a cell

A SKU like MG-012-RED packs three facts into one cell: the product type, how many come in a box and the colour. LEFT, RIGHT and MID take each piece out by its position.

ABCDE
1SKUBoxesTypePer boxColour
2MG-012-RED3MG012RED
3MG-024-BLU2MG024BLU
4TS-006-BLK5TS006BLK
5PN-100-BLU1PN100BLU
6TS-012-WHT4TS012WHT

Sample data. SKUs in A, boxes in stock in B, the formulas in C2, D2 and E2 filled down to row 6.

The first characters: LEFT

Click C2 and type:

=LEFT(A2,2)

Fill it down to C6: MG, MG, TS, PN, TS. LEFT takes the number of characters you ask for from the start of the cell.

  • Leave the number out and you get one character. Microsoft's LEFT page: "If num_chars is omitted, it is assumed to be 1." So =LEFT(A2) gives M.
  • Ask for more than the cell holds and you get the whole cell, not an error: "If num_chars is greater than the length of text, LEFT returns all of text." =LEFT(A2,20) gives MG-012-RED.

Google Sheets works the same way. Its LEFT page gives LEFT(string, [number_of_characters]), with 1 by default.

The last characters: RIGHT

In E2:

=RIGHT(A2,3)

Filled down: RED, BLU, BLK, BLU, WHT. RIGHT counts from the end of the cell, with the same two rules as LEFT on Microsoft's RIGHT page.

The middle: MID

In D2:

=MID(A2,4,3)

That says: start at character 4 and take 3. M, G and the dash are characters 1 to 3, so the result is 012. Filled down: 012, 024, 006, 100, 012.

MID always needs all three parts: the cell, where to start and how many to take. Taking more than is left is fine. Microsoft's MID page says that when the start plus the count runs past the end, "MID returns the characters up to the end of text", so =MID(A2,8,10) gives RED. Google's MID page says the same.

The result is text, not a number

The Per box column shows 012 with its zero, on the left of the cell where text goes, because LEFT, RIGHT and MID always give text. That matters when you add up: =SUM(D2:D6) gives 0, because SUM skips text (more on the SUM says 0 page). VALUE turns it into a number:

=VALUE(MID(A2,4,3))

That gives 12. Microsoft's VALUE page: it "Converts a text string that represents a number to a number." To get the units in stock, multiply by the boxes:

=VALUE(MID(A2,4,3))*B2

That gives 36, 48, 30, 100 and 48 down the column. The same page also says "Excel automatically converts text to numbers as necessary", so =MID(A2,4,3)*B2 gives 36 too: it is SUM and its cousins that skip text. All the units in one cell:

=SUMPRODUCT(VALUE(MID(A2:A6,4,3)),B2:B6)

That gives 262. One catch: VALUE drops the leading zero, so 012 becomes 12. When the piece is a code that must keep its zeros, leave it as text. The leading zeros page has more.

When the parts change length

MID by position only works while every SKU has the same shape. With MG-12-RED, PN-100-BLU, TS-6-BLK and CUP-24-GRN, =MID(A2,4,3) gives 12-, 100, 6-B and -24. Split at the dashes instead. In Excel for Microsoft 365, Excel for the web and Excel 2024:

=TEXTBEFORE(A2,"-")
=TEXTBEFORE(TEXTAFTER(A2,"-"),"-")
=TEXTAFTER(A2,"-",-1)

They give MG, 12 and RED for the first SKU, and CUP, 24 and GRN for the last. TEXTAFTER(A2,"-") is everything after the first dash, 12-RED, and TEXTBEFORE takes the part before the next dash. The -1 in the last one counts from the end; Microsoft's TEXTAFTER page: "A negative number starts searching text from the end." A SKU with no dash gives #N/A by default (TEXTBEFORE page).

Older Excel and Google Sheets: FIND gives the position of the dash, and LEFT and MID cut there:

=LEFT(A2,FIND("-",A2)-1)
=MID(A2,FIND("-",A2)+1,FIND("-",A2,FIND("-",A2)+1)-FIND("-",A2)-1)
=MID(A2,FIND("-",A2,FIND("-",A2)+1)+1,100)

FIND("-",A2,FIND("-",A2)+1) starts looking one character after the first dash, so it finds the second one: 6 in MG-12-RED. The 100 means "up to 100 characters", more than any SKU needs. Wrap the middle one in VALUE before you multiply or add. For names, the split a full name page uses the same idea with a space.

A number in front of a unit

When a cell says 12 kg and the price per kg is in B2, take everything before the space and multiply:

=LEFT(A2,FIND(" ",A2)-1)*B2

12 kg at 3.5 gives 42, 7.5 kg at 2 gives 15 and 40 kg at 0.8 gives 32. The number can be any length, because FIND looks for the space. In Excel for Microsoft 365, Excel for the web and Excel 2024, =TEXTBEFORE(A2," ")*B2 does the same.

A date gives odd digits

With 18 Nov 2026 in A2, =LEFT(A2,3) gives 463, not 18 N. Microsoft's DATE page: "Excel stores dates as sequential serial numbers so that they can be used in calculations." 18 Nov 2026 is 46344, and LEFT reads those digits, not what the cell shows. Prices work the same way: with $1,234.50 in A3, =LEFT(A3,3) gives 123, because the cell holds 1234.5. For a piece of a date, use the date functions instead:

=YEAR(A2)
=TEXT(A2,"mmm")

They give 2026 and Nov. Both work in Excel and Google Sheets.

A space in front

Data pasted from a web page or an export often starts with a space, and LEFT counts it: " Toronto" gives " To" for =LEFT(A2,3). TRIM takes the space off first:

=LEFT(TRIM(A2),3)

That gives Tor. The extra spaces page covers spaces TRIM cannot remove.

Without a formula: Flash Fill

In Excel, type the first answer next to the first row, MG next to MG-012-RED, then click the cell below it. Microsoft's Flash Fill page: "Go to Data > Flash Fill, or press Ctrl+E." Excel fills the rest of the column from the pattern. The filled cells hold plain values, not formulas, so run it again when the SKUs change, and read the column before you trust it.

Free practice sheet

Three jobs for a candle shop's stock list: the product type and the scent from each SKU with LEFT and RIGHT; the pieces in stock with VALUE and MID; and the pack size from SKUs whose parts change length, where MID by position gets most rows wrong. Yellow cells for you, a Check column that says Correct or Try again, and an Answers tab. One Excel file that opens in Google Sheets too. Free, no sign up. Sample data.

Download the practice sheet (.xlsx)

Templates with the math already done

Rather skip the formulas? These templates come with every formula built and checked, plus a filled-in sample.

Teaching this to a class or team?

Get one tip like this a month

A free email from VARS Digital with one Excel or Google Sheets fix, tested in both apps. No spam, unsubscribe any time.

By signing up you agree that VARS Digital, 10151 240 Street, Maple Ridge, BC V2W 0G9, Canada (inquiries@varsdigital.app) may email you its newsletter: Excel and Google Sheets tips, updates and news about our templates and lessons. We send a confirmation email first, and nothing else goes out until you click it. Every email has an unsubscribe link, and you can leave any time. Details in our store policies.

More how-tos