Manually isolating text within brackets in Excel is a tedious bottleneck for busy data teams. While standard funding sources and financial databases provide vital raw metrics, they often output consolidated, messy metadata strings. Automating this extraction grants analysts the ability to cleanse large datasets instantly. However, this method stipulates that each cell contains a single, matching set of square brackets. For example, extracting the cohort "FY25" from "Grant [FY25]" requires targeted string manipulation. Below, we will review the step-by-step Excel formulas to execute this text extraction effortlessly.
Excel is an indispensable tool for data analysis, but raw data is rarely perfect. Quite often, you will find yourself dealing with text strings containing valuable information locked inside brackets, parentheses, or braces. For example, you might have product list entries like Product Name [SKU-1234], contact lists formatted as John Doe (Finance), or server logs containing Error Code {ERR_502}.
Whether you need to extract the text inside those brackets, strip away excess spaces, or remove the brackets entirely, Excel provides several powerful methods to get the job done. In this comprehensive guide, we will explore both traditional and modern Excel formulas to trim and extract text inside brackets, catering to all Excel versions.
In Excel terminology, "trimming" can mean two different things depending on your objective:
We will cover both scenarios below, utilizing legacy formulas for older Excel versions (Excel 2019 and earlier) and streamlined, modern formulas designed for Excel 365 and Excel 2021.
If you are working on a legacy version of Excel or need to share your workbook with users on older versions, the combination of MID and FIND is the industry-standard solution. This formula calculates the starting position of the text inside the brackets and measures its length to pull it out precisely.
=MID(A2, FIND("[", A2) + 1, FIND("]", A2) - FIND("[", A2) - 1)
To understand this nested formula, let's break down its components using the sample text "Shipping [Priority Air]" in cell A2:
FIND("[", A2) looks for the opening bracket. In our example, the bracket is the 10th character. We add + 1 because we want our extraction to start with the character after the bracket (the "P" in "Priority"). The start position is therefore 11.FIND("]", A2) looks for the closing bracket. In our example, it is the 23rd character.MID function how many characters to extract, we subtract the starting bracket's position from the ending bracket's position and subtract 1: 23 (position of "]" ) - 10 (position of "[") - 1 = 12 characters.MID function executes: =MID(A2, 11, 12), resulting in the clean output: "Priority Air".If you are using Microsoft 365 or Excel 2021+, you can say goodbye to complex mathematical formulas. Microsoft introduced new text-manipulation functions that make extracting text between brackets intuitive and readable.
=TEXTBEFORE(TEXTAFTER(A2, "["), "]")
This approach works from the inside out:
TEXTAFTER(A2, "[") extracts everything that appears after the opening bracket. If A2 is "Shipping [Priority Air]", this inner formula yields "Priority Air]".TEXTBEFORE(..., "]") takes that result and extracts everything before the closing bracket. This strips away the closing bracket, leaving us with exactly "Priority Air".This method is not only easier to write but also vastly easier to troubleshoot and maintain.
Often, extracted text contains unwanted spaces. For example, if your source cell contains "Status [ Pending Approval ]", the formulas above will extract " Pending Approval " with spaces on both ends.
To solve this, nest your extraction formula inside Excel's native TRIM function, which automatically deletes all leading and trailing spaces, and reduces multiple consecutive middle spaces to a single space.
=TRIM(MID(A2, FIND("[", A2) + 1, FIND("]", A2) - FIND("[", A2) - 1))
=TRIM(TEXTBEFORE(TEXTAFTER(A2, "["), "]"))
What happens if a cell doesn't contain brackets at all? For instance, if A2 simply says "Ground Shipping".
Without error handling, the FIND and TEXTBEFORE functions will fail and return a frustrating #VALUE! or #N/A error. To keep your spreadsheets clean and professional, wrap your formulas in the IFERROR function. This allows you to define a fallback value (such as a blank cell or a custom message) if no brackets are found.
=IFERROR(TRIM(MID(A2, FIND("[", A2) + 1, FIND("]", A2) - FIND("[", A2) - 1)), "")
=IFERROR(TRIM(TEXTBEFORE(TEXTAFTER(A2, "["), "]")), "")
Tip: Replace "" with a descriptive term like "No Brackets Found" if you want to actively flag missing data.
Not all data uses square brackets. Fortunately, these formulas are highly adaptable. You simply need to replace the opening and closing delimiters within the formulas to match your data structure.
| Bracket Type | Target Delimiters | Modern Excel Formula (M365) | Classic Excel Formula |
|---|---|---|---|
| Parentheses | ( and ) |
=TEXTBEFORE(TEXTAFTER(A2, "("), ")") |
=MID(A2, FIND("(", A2)+1, FIND(")", A2)-FIND("(", A2)-1) |
| Curly Braces | { and } |
=TEXTBEFORE(TEXTAFTER(A2, "{"), "}") |
=MID(A2, FIND("{", A2)+1, FIND("}", A2)-FIND("{", A2)-1) |
| Angle Brackets | < and > |
=TEXTBEFORE(TEXTAFTER(A2, "<"), ">") |
=MID(A2, FIND("<", A2)+1, FIND(">", A2)-FIND("<", A2)-1) |
Sometimes, your data cells contain multiple bracketed items, such as: "User [JDoe] Role [Admin]".
If you want to extract the content of the second set of brackets (e.g., "Admin"), the modern TEXTAFTER function makes this incredibly simple via its optional [instance_num] argument.
=TEXTBEFORE(TEXTAFTER(A2, "[", 2), "]")
By putting a 2 as the third argument in TEXTAFTER, Excel skips the first opening bracket and targets the text following the second opening bracket.
If you want to extract every single piece of bracketed text into its own column dynamically, you can combine TEXTSPLIT and TRIM:
=TEXTSPLIT(A2, {"[","]"}, , TRUE)
This powerful dynamic array formula splits the text wherever it encounters an open or close bracket, and automatically filters out empty strings, placing each clean value into neighboring cells.
Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.