Pulling First Letters from Parenthetical Text

Written by Allen Wyatt (last updated September 27, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


1

Tom has a worksheet that contains quite a bit of text. He needs a way to pull, from any given cell's text, the first letter of each word within parentheses. For instance, if a cell contains "There is a weed (during the spring) that needs to be eradicated", then Tom needs to pull "dts" from that text. He suspects this must be done with a macro but doesn't know where to start.

If you wanted to perform this task manually, it isn't that difficult to accomplish. I'll go through the steps quickly and generally.

Let's assume that your text is in column A and that each cell contains only a single set of parentheses. In this case you could put the following in column B:

=IFERROR(LEFT(MID(A1,FIND("(",A1)+1,LEN(A1)),FIND(")",
MID(A1,FIND("(",A1)+1,LEN(A1)))-1),"")

Even though I've broken the formula to two lines here, remember that it is a single formula and should be entered as such. Copy it down as many cells as necessary. What you end up with in column B is the text contained with the first set of parentheses (if any) if the cell.

Next, select all the cells in column B, press Ctrl+C, and then use Paste Special to paste values back into those cells. This gets rid of the formulas but leaves the extracted parenthetical text.

Now the cells in column B should still be selected. You want to use the Text to Columns wizard (from the Data tab of the ribbon) to split the words out into individual cells. This is easy to do using a space as a delimiter in the wizard. After doing this, you end up with a single word in each column starting with column C.

Now, in the first column that doesn't have any words in it (let's say that is column J) you would enter the following formula:

=LEFT(TRIM(C1),1) & LEFT(TRIM(D1),1) & LEFT(TRIM(E1),1)
& LEFT(TRIM(F1),1) & LEFT(TRIM(G1),1)) & LEFT(TRIM(H1),1)
& LEFT(TRIM(I1),1)

Again, this is a single formula even though it is shown here on three lines. This results in your desired first letters in column J.

Obviously, this process is "doable" if you only need to pull the letters every once in a while. If you need to do it more often, then you would be better served to rely on a user-defined function to do the work for you. The following is a simple one that will work just fine:

Function PickInitials(sRaw As String) As String
    Dim sTemp As String
    Dim J As Integer
    Dim Wds() As String

    sTemp = ""
    J = InStr(sRaw, "(")
    If J > 0 Then
        sTemp = Mid(sRaw, J + 1)
        J = InStr(sTemp, ")")
        If J > 0 Then
            sTemp = Left(sTemp, J - 1)
        End If
        Wds = Split(sTemp)

        sTemp = ""
        For J = 0 To UBound(Wds)
            sTemp = sTemp & Left(Trim(Wds(J)),1)
        Next J
    End If
    PickInitials = sTemp
End Function

To use the function, all you need to do is to use the following in a cell:

=PickInitials(A1)

The function will work just fine if there is no parenthetical text in the cell, if there is only an opening parenthesis, and it will not be thrown by multiple spaces between words. The function retains the capitalization of the initial letters. If you want it to return all the letters as lowercase, you could change the final line of the macro to this:

    PickInitials = LCase(sTemp)

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13622) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Text Truncated in PivotTable

When you create a PivotTable based on data that contains lots of text, you may be surprised to find that your text is ...

Discover More

Can't Merge Alphanumeric Data Correctly

When you merge data from Excel into a Word document, you may need to do some conditional processing based on the data you ...

Discover More

Moving Part of a Footer Down a Line

Setting up a single footer line for your printouts is fairly easy. If you want to move part of the footer down a line so ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Generating a Keyword Occurrence List

Need to pull a list of words from a range of cells? This tip shows how easy you can perform the task using a macro.

Discover More

Out of Memory Errors when Accessing the VBA Editor

It can be frustrating when you get error messages doing something that you previously did with no errors. If you get an ...

Discover More

Copying Named Ranges

Named ranges are a great tool to use in developing formula-heavy workbooks. You may want, at some point, to copy your ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is nine minus 1?

2019-02-16 15:02:52

Balkee

Good solutions, but the first solution has a manual step in between that can be avoided thus:
C1: =0
D1: =SEARCH(" ",$B1,C1+1)
E1: =SEARCH(" ",$B1,D1+1)
F1: =SEARCH(" ",$B1,E1+1)
G1: =SEARCH(" ",$B1,F1+1)
and so on, for a "reasonable number of columns)
Then,
Z1: =IFERROR(MID($B1,C1+1,1),"")
&IFERROR(MID($B1,D1+1,1),"")
&IFERROR(MID($B1,E1+1,1),"")
&IFERROR(MID($B1,F1+1,1),"")
&IFERROR(MID($B1,G1+1,1),"")
and so on, depending on the last "reasonable" column used above

Example values with the above formulae:
A1: There is a weed (during the spring that needs) to be eradicated Z1: dtstn
A1: There is a weed (during the spring that) needs to be eradicated Z1: dtst
A1: There is a weed during the spring that needs to be eradicated Z1:


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.