Excel: How to Isolate the Center Portion of an Account ID

This page is an advertiser-supported excerpt of the book, Power Excel 2010-2013 from MrExcel - 567 Excel Mysteries Solved. If you like this topic, please consider buying the entire e-book.


Problem: My company assigns an account ID in the format SSS-XX-YYYY. I need to isolate the XX portion of the account ID in order to subtotal or sort the data.

  1. Use a formula to extract the middle of the account ID.

    Strategy: You can insert a new column and use the MID function to isolate the necessary digits from the Account field.

    The MID function takes three arguments: (1) a cell that contains a text value, (2) the character number where you want the result to start, and (3) the length of the result.

    In a well-formed account number, such as 123-45-6789, you can predict that the start of the second segment will always be in the fifth character position and the length of the second segment is always two characters. Therefore, you can follow these steps:

    1. In a blank column, such as column G, enter a heading such as Key.
    2. In cell G2, enter the formula =MID(A2,5,2).
    3. Copy the formula down to all rows.

  2. Get the middle text, starting at position 5, for a length of 2.

    Additional Details: In order to capture the final four digits of the account number, you could either use =MID(A2,8,4) or =RIGHT(A2,4).

    Results: You can now sort by the new column and add subtotals based on the Account field.