Importing data into Excel from other systems rarely goes without the need to fix formatting before you can even use it.
Sandy R from Pittsburgh, PA sent in this Excel Factor entry.
Using the REPT, LEN, FIND and MID functions Sandy can transform thousands of rows of data that comes into Excel like this:
To a xxxxxxx.xxxxxxx format like this:
Let’s say Sandy’s data is in column A and formatted as Text (this is important for the formula to work). The formula she uses looks like this:
Yikes! Actually it’s not that scary. Let me translate it into English;
Find the characters in front of the full stop, count how many characters there are, then take the number of characters up to 7 by adding zeros to the front of the characters in front of the full stop. Then add a full stop. Do the same for the characters after the full stop.
Obviously Excel doesn’t solve the formula in this order but I think it helps to know that this is what you are trying to achieve.
To understand how it works we’ll take a look at each function in the first part of the formula (up to the &MID...) using the first item in Sandy's list (3707.314278) as our example:
The FIND function returns the starting position of one text string within another text string. FIND is case-sensitive.
=FIND(find_text, within_text, [start_num])
In Sandy’s formula she is finding the location of the full stop like this:
The result: 5 i.e. the full stop is the 5th character.
Note how Sandy hasn’t entered a start_num argument. This is because the start_num is optional. You can tell it is optional because it is in [square brackets].
The start_num is the character you want to start the search from. The first character in within_text is 1. If the argument is omitted it will start at the beginning of within_text.
The MID function returns the characters from the middle of a text string, given a starting position and length.
=MID(text, start_num, num_chars)
In Sandy’s formula:
The result =MID(A2,1,5-1)
The end result are the first 4 characters: 3707 (these are text not numbers)
The LEN function returns the number of characters in a text string.
Sandy’s uses MID and FIND to tell Excel which text she wants to find the length of.
The result: =LEN("3707."-1)
=LEN(5-1) i.e. how long is the text up to and including the full stop, then take 1 off so that we don't count the full stop.
The REPT function repeats text a given number of times.
In Sandy’s formula:
This section of the formula evaluates to:
=REPT(0,3) i.e. repeat the zero 3 times.
Sandy then uses the ampersand (&) with MID to concatenate her new text together with a full stop in between.
The second half of the formula is slightly more complicated because it needs to start after the full stop, but now that you know how MID, FIND, LEN and REPT work you can figure out the rest for homework 🙂
The Non-Formula Approach
Now, if you want a less brain intensive option that’s only slightly more laborious you could do it this way:
- Use Text to Columns to separate the two halves of the data using the full stop as a delimiter.
- Apply a custom number format 0000000 to your two new columns D and E.
- Copy the new data and paste it into Notepad (free in your Windows Accessories folder).
- Copy it out of Notepad and paste it back into Excel as Text (Paste Special > Text).
- Use CONCATENATE or the ampersand to join the text back together with a full stop in between. Ok, so it uses one tiny formula.
Note: if this is something you have to do regularly then it is worth taking the time to get your head around a formula like Sandy’s as this is the quickest long term solution.
Thanks for sharing your mammoth formula with us, Sandy.
Sandy R works for a law firm in Pittsburgh, PA and does a combination of IT and Library Science duties. She has used Excel for the last eight years, not only in her current job but also in previous jobs.
Vote for Sandy R
If you’d like to vote for Sandy’s tip (in X-factor voting style) use the buttons below to Like this on Facebook, Tweet about it on Twitter, +1 it on Google, Share it on LinkedIn, or leave a comment….or all of the above 🙂