Written by Allen Wyatt (last updated October 5, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365
Terry has a huge list of names in an Excel worksheet. Some are just the names, but some have words in brackets after them. Unfortunately, some of the words in brackets don't have the closing bracket and Terry has to manually add the closing bracket. He wonders if there is a way that he can add a bracket using a wild card search and replace.
The short answer is that you can't do this using a search and replace, either wild card or regular. You can, however, use a formula to add any missing brackets. The following is just one example of the type of formula you can use:
=IF(AND(NOT(ISERROR(SEARCH("[",A1))),NOT(RIGHT(A1,1)="]")),A1&"]",A1)
The trick is to check to see if the cell (A1 in this case) has a left bracket in it and, if it does, check for the right bracket. If the right bracket isn't found, then you append one to the contents of the cell. Here's another variation on the same formulaic theme:
=IF(ISERROR(FIND("[",A1)),A1,IF(ISERROR(FIND("]",A1)),A1&"]",A1))
If you have to check large numbers of cells for missing brackets on a regular basis, you may want to create a macro that will examine a range of cells and add a right bracket if one is needed. Here's an example of how such a macro could be formulated:
Sub Close_Bracket() Dim c As Range Const csLBrk As String = "[" Const csRBrk As String = "]" On Error Resume Next For Each c In Selection.Cells If InStr(1, c.Value, csLBrk) > 0 And _ InStr(1, c.Value, csRBrk) = 0 Then c.Value = c.Value & csRBrk End If Next c End Sub
To use the macro, simply select the range of cells you want to affect, and then run it. The cells are examined in-place and modified, if needed.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (126) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, 2021, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Adding a Missing Closing Bracket.
Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!
Need a bit of help in figuring out how Excel is evaluating a particular formula? It's easy to figure out if you use the ...
Discover MoreDo you want to insert the name of your Excel workbook into a cell? There are a number of ways you can do this, as ...
Discover MoreWhen you edit a worksheet, adding and deleting rows and columns, Excel automatically updates references to cells ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments