Splitting text in excel using formulas
Often when you are processing text using excel it is important to split the text in to multiple parts based on a delimiter. For eg. you may want to divide
this|needs|to|be|split in to five parts
this needs to be split. There is a simple way to do this in excel, using “import text” option. But this is not always preferable, especially if you need to split text as part of a large process, then you may want to do this using formulas.
Here is a simple approach that you can use to split text using find() and mid() spreadsheet formulas.
Assuming the text you want to split is in Cell B2 and the delimiter is space ” “,
- First we need to find which locations in the text has space in them. Using find() we can do this. So, in cell c2 we will write our first find() as
find(" ",$b$2)and in cell d2 we will write
find(" ",$b$2,b3+1). Now we can copy cell D2 and paste in cells E2, F2 … n2.
- Now in Row 3, we will get the split text using a simple MID() spreadsheet formula. In cell B3, the formula would look like,
=mid($B$2,1,C$2)and from C3 onwards we can use a formula like
=mid($B$2,C2,if(iserror(D2),99,D2-C2)). Essentially what we are doing is, for the first split of the text we are using 1 as starting position and C$2 (location of first space in the text) as the ending position. For the subsequent splits we are using previous space as starting position.
- That is all. The good thing with this technique is that you just need to write 2 different formulas and then you can use copy paste to get all the text splits. Of course you may want to use some error handling like I did to avoid #value errors.
Do you want to be awesome in Excel?
Here is a smart way to become awesome in Excel. Just signup for my Excel newsletter. Every week you will receive an Excel tip, tutorial, template or example delivered to your inbox. What more, as a joining bonus, I am giving away a 25 page eBook containing 95 Excel tips & tricks. Please sign-up below:
Your email address is safe with us. Our policies
More awesome tips for you:
Leave a Reply
|Either the glasses are floating or you are drunk – Photographic Fridays # 12||Excel links of the week [Sep 8]|