Yikes! Actually it’s not that scary. Let me translate it into English;

Find the characters in front ofthe 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:

FIND Function

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:

FIND(".",A2)

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.

MID Function

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:

=MID(A2,1,FIND(".",A2)-1)

The result =MID(A2,1,5-1)

The end result are the first 4 characters: 3707 (these are text not numbers)

LEN Function

The LEN function returns the number of characters in a text string.

=LEN(text)

Sandy’s uses MID and FIND to tell Excel which text she wants to find the length of.

=LEN(MID(A2,1,FIND(".",A2)-1))

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.

REPT Function

The REPT function repeats text a given number of times.

=REPT(text, number_times)

In Sandy’s formula:

=REPT(0,7-LEN(MID(A2,1,FIND(".",A2)-1)))

This section of the formula evaluates to:

=REPT(0,7-LEN(5-1))

=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.

&MID(A2,1,FIND(".",A2)-1)&"."&

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.

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 🙂

Comments

I have a text that looks looks this:
R1_LUT X,Y 0.3, -1.7 OR at time can also look like this:
R1_LUT X,Y -0.3, -1.7
I want to extract 0.3 as well as -0.3, using one robust formula, because the numbers could appear with signs OR without signs.
I used the mid function =MID(A64,14,4) and it works well, but for the string in the first line, I end up with 0.3, and I don’t need the comma here.
Can someone help me with using a conditional MID function, that will take care of both scenarios, to give me 0.3 as well as -0.3

Hello Mynda.
Wow! Thanks for your reply.
However, my numbers could be anything, not just a 0.3 or a-0.3.
i.e. I am looking to make this more generalized:
R1_LUT X,Y 0.3, -1.7 So—R1_LUT X,Y is always going to appear in the line, but the two set of numbers could be anthing as well as could be signed or unsigned(but will always be seperated by commas)
Can you help me with a more generalized formula, using comma as a leverage in the formula?

If I were you I’d use the Text to Columns tool as opposed to writing a long complex formula that has to handle multiple scenarios. If the last letter before your value is ‘Y’ you can use ‘Y’ as the delimeter which will give you the last half of your text, then you can run it through text to columns again and use the comma as the delimeter to get rid of the text on the end.

Since this manipulates the data as text only, it might have been better if you used text in the example, and not number that were going to be treated as text by Excel. Just to avoid confusion.

With that said, how do I accomplish the same feats that I would use ‘mid’ for, but having the output be usable numbers, and not numbers that Excel thinks is text? (I ended up having to do a “a1+a1-a1” game to convince Excel that what was in the a1 cell was actually a usable number.)

What do you mean exactly by “a1+a1+a1”? As far as I know, and as what I’ve double-checked– your
complaint–, I don’t get that type of result unless through concatenation “a1&a1&a1”. But
adding texts would result VALUE# error.

Anyway, even as texts, numbers get treated as numbers by excel except that they’re indented
to the left instead of to the right.

But I’m not closing this one without a neat solution:
Data E5: 12432
Use INT or VALUE(if you have decimals)

=INT(MID(E5,1,3)) or =VALUE(MID(E5,1,3))
=INT(MID(E5,1,4)) or =VALUE(MID(E5,1,4))
result: 4 + 3
All indented to the right and behaving like numbers
as they should.

OR….

Maybe, you need to:
1) Go to Excel Options
2) Click Advanced
3) Scroll down to : Display options for this worksheet
4) Uncheck: Show Formulas in cells instead of their
calculated results
5) It would also help by copying and pasting them as values
and converting them to numbers/numeric formats.

Nice tip indeed! I tried to re-use some of it for a problem I have at work but did not manage to make it work! I need to only select part of the text written as below:
US60/TAT520,423
US60/PEL588N,508
I would like to extract only the middle text TAT520 or PEL588N. The issue is that the number of letters or figures are not always the same. Only “US60/” and “,423” is fixed (text or figures can change but it’s always 4 letters or figures + / and ,+3 figures). I managed to extract only TAT520,423 using =MID(D5,FIND(“/”,D5)+1,LEN(D5)-4) but I could not get rid off the ,423 too. Would you know how to do this Mynda?
Thanks for your help.
Karine

Resources

Affiliate Program

Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.

✕

Hang On, Don't Go Just Yet.

As a thank you for visiting how would you like a10% Discount Code to use with any of my courses?