top of page

Extracting text around a string in Excel

If you need to extract text from an Excel cell which is X number of characters before and Y number of characters after a given search term, you can use the MID and MAX formulas with a nested SEARCH formula.


A formula in this format:


=MID(A2,MAX(SEARCH("stole a",A2)-35,1),70)


. . . can be set to return the number of characters before the search string equal to the value given in the MAX formula (in this example 35) and the number of characters from the start of the search string moving to the right equal to roughly half the value given for the MID formula (in this example 70).



. . . the SEARCH formula finds the position in the cell containing text where the first character of the search term appears.



The MAX formula then gets the value of the SEARCH result minus the number entered in the complete formula. In this it is case 35.



When the result from the MAX formula is fed into the MID formula, it is used to determine the position where the extraction should begin, and how many characters after that point it should include.



Sean O'Shea has more than 20 years of experience in the litigation support field with major law firms in New York and San Francisco.   He is an ACEDS Certified eDiscovery Specialist and a Relativity Certified Administrator.

The views expressed in this blog are those of the owner and do not reflect the views or opinions of the owner’s employer.

If you have a question or comment about this blog, please make a submission using the form to the right. 

Your details were sent successfully!

© 2015 by Sean O'Shea . Proudly created with Wix.com

bottom of page