When you are dealing with poorly formatted datasets in Microsoft Excel, you often encounter cells that merge multiple pieces of information together. For example, a single cell might contain a product code followed by a description, like “AB123_Wireless_Mouse”. If you only need to extract the 5-character product code at the beginning of the string to run an inventory match, manually deleting the descriptions from thousands of rows is impossible. You can fully automate this extraction using the LEFT function.
How the LEFT Function Works
The LEFT function is a precise text manipulation formula. It looks at a target cell, anchors itself to the extreme left edge of the text string, and then counts outward. It extracts exactly the number of characters you specify, leaving the rest of the text behind.
The core syntax is: =LEFT(text, [num_chars])
- text: The cell containing the messy data (e.g., A2).
- num_chars: The exact number of characters you want to slice off, counting from the left side.
How to Extract a Fixed Number of Characters
If your data is strictly uniform—meaning every single product code in your dataset is exactly 5 characters long—the formula takes two seconds to deploy.
- Create a blank column immediately to the right of your messy data (e.g., Column B).
- Click into cell B2 and type:
=LEFT(A2, 5) - Press Enter. Excel will immediately strip away the description and output just “AB123”.
- Click on cell B2 again. Hover your mouse over the small green square in the bottom right corner (the Fill Handle) until your cursor turns into a black cross.
- Double-click the Fill Handle. Excel will instantly copy the
LEFTformula down through all 5,000 rows of your dataset.
How to Extract Dynamic Character Lengths
The basic LEFT function breaks if the data length varies. If row 1 is “AB123_Mouse” and row 2 is “XYZ98765_Keyboard”, a hardcoded =LEFT(A2, 5) will incorrectly chop the second code in half.
To fix this, you must combine LEFT with the FIND function. The FIND function will hunt for the underscore character (_) that separates the code from the description, dynamically determining where the cut should happen.
=LEFT(A2, FIND("_", A2) - 1)
This advanced formula asks Excel to find the numerical position of the underscore, subtracts 1 (so the underscore itself is not included in the extraction), and passes that exact character count to the LEFT function, perfectly extracting every product code regardless of its length.