Function Problems

How to Extract Text from the Last Square Bracket in Excel

Steve KSteve K Nov 3, 2026 870 views

Question details

The user needs an Excel formula to extract the string located inside the final set of square brackets within a cell containing multiple bracketed texts.

Extracting Text from the Last Square Bracket in Excel
Product
Excel
Device & OS
not provided
Scenario
Data cleaning or text manipulation where specific data is trapped inside the last pair of brackets in a messy text string.
Observed behavior
The user requires a formula that accurately identifies the last opening and closing square brackets and returns only the text between them.
Before you start

Ensure your dataset is backed up before applying complex text extraction formulas. Verify that the cells you are targeting actually contain at least one set of square brackets to avoid formula calculation errors.

Solution 1Recommended

Using the TRIM, SUBSTITUTE, and REPT Formula

This highly effective formula replaces the target brackets with large spaces, making it easy to isolate the last bracketed section regardless of string length.

This solution works seamlessly across all Excel versions without needing the latest dynamic array functions. By using REPT to add 255 spaces where the brackets are, RIGHT and LEFT functions can easily grab the desired segment.

1
Select the target cell

Click on an empty cell adjacent to your data where you want the extracted text to appear.

2
Enter the formula

Type the formula: =TRIM(LEFT(SUBSTITUTE(TRIM(RIGHT(SUBSTITUTE(G2,"[",REPT(" ",255)),255)),"]",REPT(" ",255)),255)) replacing 'G2' with your actual cell reference.

3
Execute the formula

Press Enter to execute the formula and view the extracted text.

4
Apply to multiple cells

Click and hold the small green square at the bottom right corner of the cell, then drag the fill handle down to apply this formula to other cells in your column.

Using the TRIM, SUBSTITUTE, and REPT Formula
How it works: The REPT function pads the text with 255 spaces around the opening bracket. The RIGHT function then pulls the last 255 characters, successfully isolating the last bracketed portion. The outer formulas clean up the trailing closing bracket and extra spaces.
Edit Spreadsheets Effortlessly

Easily Extract Text with WPS Spreadsheet

WPS Office Spreadsheet fully supports advanced text formulas like TRIM, SUBSTITUTE, LEFT, and RIGHT, making it simple to process complex strings and clean your data efficiently without buying expensive software.

  1. 1. Download and Install: Download and install WPS Office for free from the official website.
  2. 2. Open your workbook: Open your existing Excel workbook (.xlsx or .xls) directly in WPS Spreadsheet.
  3. 3. Input the formula: Select the target cell and input the exact text extraction formula (=TRIM(LEFT(...))) just as you would in Microsoft Excel.
  4. 4. Apply and drag: Press Enter to extract the text, and drag the fill handle down to apply the extraction across your entire dataset.
Fully compatible with Microsoft Excel formulas, functions, and file formatsFree, lightweight, and easy to install on any deviceFamiliar user interface for seamless and quick text extraction
microsoft office alternative - wps office

Frequently Asked Questions

Why does my formula return an error if there are no brackets in the cell?

Text extraction formulas look specifically for the '[' and ']' characters. If they are missing, the FIND or SUBSTITUTE functions cannot locate them, resulting in a #VALUE! error. You can fix this by wrapping your entire formula in an IFERROR function, like =IFERROR(your_formula, ""), to return a blank cell instead of an error.

Can I modify the formula to extract text from regular parentheses instead?

Yes. Simply edit the formula and replace the square brackets '[' and ']' with regular parentheses '(' and ')'. The logical steps for isolating the last set of characters will remain exactly the same.

Is there a simpler way to do this in newer versions of Excel?

In Microsoft 365, you can use modern text functions like TEXTAFTER and TEXTBEFORE. To extract text inside the last set of square brackets, you can use a formula combination relying on TEXTAFTER(G2, "[", -1) to grab everything after the last opening bracket.