Day(s)

:

Hour(s)

:

Minute(s)

:

Second(s)

How To Find The First Number In A Text String

In this post we’re going to find out how to get the position of the first number within a text string. Let’s suppose we have stock level data for a grocery store and in our example someone has gone and put both the item and stock quantity in one cell making it difficult to use the data. How can we easily separate this data into two cells?

 

step-001-how-to-find-the-first-number-in-a-text-string

 

Copy and paste this table into cell A1 in Excel

Item & QuantityPositionText To LeftText To Right
Pineapples260=MIN(FIND({0,1,2,3,4,5,6,7,8,9},A2&”0123456789″))=LEFT(A2,B2-1)=RIGHT(A2,LEN(A2)-B2+1)
Gala Apples20=MIN(FIND({0,1,2,3,4,5,6,7,8,9},A3&”0123456789″))=LEFT(A3,B3-1)=RIGHT(A3,LEN(A3)-B3+1)
Bananas6=MIN(FIND({0,1,2,3,4,5,6,7,8,9},A4&”0123456789″))=LEFT(A4,B4-1)=RIGHT(A4,LEN(A4)-B4+1)
Grape Bunch56=MIN(FIND({0,1,2,3,4,5,6,7,8,9},A5&”0123456789″))=LEFT(A5,B5-1)=RIGHT(A5,LEN(A5)-B5+1)

 

First to find the position of the first numeric character, we can use this formula.

=MIN(FIND({0,1,2,3,4,5,6,7,8,9},A2&"0123456789"))

This will find the position of the first instance of one of the elements of the array {0,1,2,3,4,5,6,7,8,9} (i.e. the first number) within cell A2 (our text data). The &”0123456789″ part ensures the FIND function will at least find a number if A2 does not actually have a number in it and will allow the formula to calculate without resulting in a #VALUE error.

 

We can then use this position we have just calculated to return the text to the left (the item) and the text to the right (the quantity).

 

Text to the left can be found with this formula.

=LEFT(A2,B2-1)

 

Text to the right can be found with this formula.

=RIGHT(A2,LEN(A2)-B2+1)

 

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and qualified actuary with over 15 years of experience. He has worked in a variety of industries, including insurance, ad tech, and most recently Power Platform consulting. He is a keen problem solver and has a passion for using technology to make businesses more efficient.

Subscribe

Subscribe for awesome Microsoft Excel videos 😃

John MacDougall

I’m John, and my goal is to help you Excel!

You’ll find a ton of awesome tips, tricks, tutorials, and templates here to help you save time and effort in your work.

Related Posts

37 Awesome Excel Mouse Tips & Tricks You Should Know

37 Awesome Excel Mouse Tips & Tricks You Should Know

While the keyboard is generally quicker, you shouldn’t completely ignore the mouse. There are also some great time saving mouse shortcuts as well. In this post we’ll take a look at some of the best Excel mouse time saving tips and tricks.

read more
25 Amazing Power Query Tips and Tricks

25 Amazing Power Query Tips and Tricks

Power query is amazing tool that allows you to import and transform data with ease and helps to create repeatable and robust procedures with your data. Here are some tips and tricks to help you get the most out Power Query.

read more

Comments

3 Comments

  1. Brian

    I tried cutting and pasting the example into Excel, and it didn’t work. I finally figured out the issue is that the font used here converted the quotation marks to characters that Excel didn’t recognize: ” ″. I changed them to ” and it worked fine.

    • John

      Yes, unfortunately WordPress and Excel use a different quote character.

  2. Aaron

    Works great!

Get the Latest Microsoft Excel Tips

Follow Us

Follow us to stay up to date with the latest in Microsoft Excel!

Subscribe for awesome Microsoft Excel videos 😃