In the previous post, we talked about the basic of Text to Columns and focused on “Fixed width”. In this post, we will continue to talk about three magical things that Text to Columns could do with ease:
- Extract part of text string with delimiter(s)
- Convert numbers with trailing minus, e.g. “123-” into number
- Convert numbers with “,” (comma) as decimal point into number
You may probably know about the first one, but be honest did you also know the second and third one? 🙂 Let’s take a quick tour to all of them.
You may download the Sample File – Text to Columns (2) to follow through.
Extract part of text string with delimiter (s)
Situation: This is quite common, I guess. Let’s continue with the example discussed in the previous post. The task is to extract Latitude and Longitude from the text string in column A:
No matter whether we deploy “Fixed width” or “Delimited”, we will go through the 3 steps of the Text to Columns Wizard. But first of all, we need to select the range of data before activating the Wizard:
- Go to Data –> Text to Columns –> Select “Delimited”
- Select “Comma” as Delimiter
ooops… Something went wrong as seen in the “Data preview” because we had another delimiter “|” there
- Did you notice that the word “Delimiters” comes with “s”… Check the “Other:” and specify “|”
- Since we do not need “Date”, we may “Skip” that column.
- And we want to extract the data into new column, we have changed the Destination to G2.
- Here we go.
The advantage of “Delimited” over “Fixed width” is obvious. It is applicable to most of the real world data that is
- of different length;
- separated by a common delimiter, e.g. comma, tab.
As illurstrated in the above example, Text to Columns can deal with more than one delimiters (up to 5). Having said that, I hope you would never encounter a situation where you need to check more than 2 delimiters in Step 2 of the Wizard. In my experience, the more delimiters you need, the less chance you will get your expected result. 🙂
Convert numbers with trailing minus
Situation: You download some txt. file from an accounting system… you are surprised that all negative numbers are recorded with trailing minus, e.g. 123-. All these numbers are treated as “text” and you cannot do simple calculation such as SUM as a result. How frustrating it is…
No worry! Text to Columns to rescue.
In step 3 of the Wizard, there is an “Advanced…” button for data of “General” format. Select the column of data with trailing minus, follow the steps below:
wow… it’s done! Can’t believe it is as simple as that.
Convert numbers with a different decimal point
Situation: You work in a multi-national company. And you know there are many countries in this world where they use a comma “,” (not “.” dot) as a decimal separator in the number. You receive txt. file that store numbers in that way, i.e. 2,30 means 2.30 to you but a text string of “2,30” to Excel. OMG… you can’t SUM these numbers. 😦
Again, Text to Columns to rescue.
In our previous example of using “Advanced…” in step 3 of the wizard, did you notice that you can specify Decimal / Thousand separator?
wow… again as simple as this.
Tip: We can do the conversion in a reversed direction.
Limitation of Text to Columns
Results are static. When new data comes or original data changed, you may need to go through the same process again. Power Query fixes this limitation. In Power Query, we can “record” the steps, when data changes or updates, a click of “Refresh” does all the magic.
goo day: suppose on column A i have entries and on column B i have due dates for the entries. Is it possible to have excel automatically rearrange the ROWS such that the nearest dates appear at the top and the furthest dates at the bottom? Thank you in advance
LikeLike
Hi Sidney
Not sure if I have understood correctly… do you mean sort by column B? Or you want to sort against due dates vs. today?
LikeLike
Hi MF. Thanks for your response, much appreciated. i want to have excel automatically sort against due dates vs today
LikeLike
Can you use a helper column?
LikeLike
https://wmfexcel.com/2017/12/03/get-a-list-of-pending-tasks-and-sort-by-due-dates/
Hi Sidney, check this out and see if it helps.
Cheers,
LikeLike
Good day, i need help: how to search for cells that contain only a specific text e.g. cell A1 contains 5A;5AB;5AC and Cell C1 contains 6A;5AB;6C. Now, if you search for 5A in Excel, it will return both A1&C1 as cells that contain 5A. How do i limit it to only return cell A1? Please help
LikeLike
How cna you split one cell has wrap text into others columns in using text to Columns format??
Sent: Friday, October 13, 2017 at 8:03 PM
LikeLike
Hi Frank,
Do you mean something like this?
https://wmfexcel.com/2015/06/27/how-unorganized-data-could-drive-you-crazy/
LikeLike