+ Reply to Thread
Results 1 to 14 of 14

formula to find starting position and count numbers in a string

  1. #1
    Registered User
    Join Date
    10-30-2009
    Location
    sacramento, ca
    MS-Off Ver
    Excel 2010
    Posts
    12

    formula to find starting position and count numbers in a string

    Hi,

    I need a formula that will find the position of the first number in a string, and how many characters are in that number. For instance, it should return 2 and 6 for the value below.

    T106300 7/14-7/15/16 GRT DEAN

    I found this formula to get the position of the first number: =MIN(IF(ISNUMBER(FIND({0,1,2,3,4,5,6,7,8,9},A1)),FIND({0,1,2,3,4,5,6,7,8,9},A1)))

    I need help with the second part.

    Thanks for your help,

    Craig

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: formula to find starting position and count numbers in a string

    I am not very good at these formulas yet.

    But this in B1 will give you the position of the first number in A1

    Then all you need to do is find the first space or space after the first position.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    This formula in C1 will give you the number of numbers.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by mehmetcik; 04-04-2017 at 07:23 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: formula to find starting position and count numbers in a string

    You can use your first formula:
    =SEARCH(" ",A1,MIN(IF(ISNUMBER(FIND({0,1,2,3,4,5,6,7,8,9},A1)),FIND({0,1,2,3,4,5,6,7,8,9},A1))))-MIN(IF(ISNUMBER(FIND({0,1,2,3,4,5,6,7,8,9},A1)),FIND({0,1,2,3,4,5,6,7,8,9},A1)))
    or use result of the first formula (in this case: 2): =SEARCH(" ",A1,2)-2 or =SEARCH(" ",A1,B1)-B1 where B1=result of the first formula
    Last edited by sandy666; 04-04-2017 at 06:58 PM.

  4. #4
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: formula to find starting position and count numbers in a string

    With that sample...
    T106300 7/14-7/15/16 GRT DEAN


    what would your expected outcome be?
    106300 7/14-7/15/16
    or
    106300
    or something else?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  5. #5
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: formula to find starting position and count numbers in a string

    Maybe something like this?

    Formula: copy to clipboard
    Please Login or Register  to view this content.



    A
    B
    1
    T106300 7/14-7/15/16 GRT DEAN
    106300
    Dave

  6. #6
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: formula to find starting position and count numbers in a string

    Shorter version:
    Position of the first number in the string:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Length of the first numbers string:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    based on OP's example post #1
    Last edited by sandy666; 04-04-2017 at 08:42 PM.

  7. #7
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: formula to find starting position and count numbers in a string

    Another way to get first number.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    and to get first 6 numbers this array formula If you aren’t familiar with array-entered formulas array enter means the formula must be committed from edit mode by simultaneously pressing and holding down Ctrl and Shift while hitting Enter.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  8. #8
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: formula to find starting position and count numbers in a string

    My sugesstion:

    First position:
    =MIN(IFERROR(SEARCH(ROW($1:$10)-1,A1),""))

    Lenght:
    =LEN(MAX(IFERROR(MID(A1,MIN(IFERROR(SEARCH(ROW($1:$10)-1,A1),"")),ROW(INDIRECT("1:"&LEN(A1))))+0,"")))

    in which, first number is:
    =MAX(IFERROR(MID(A1,MIN(IFERROR(SEARCH(ROW($1:$10)-1,A1),"")),ROW(INDIRECT("1:"&LEN(A1))))+0,""))

    All are confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.
    Quang PT

  9. #9
    Registered User
    Join Date
    10-30-2009
    Location
    sacramento, ca
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: formula to find starting position and count numbers in a string

    Post deleted
    Last edited by craig04; 04-07-2017 at 04:11 PM.

  10. #10
    Registered User
    Join Date
    10-30-2009
    Location
    sacramento, ca
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: formula to find starting position and count numbers in a string

    Post deleted
    Last edited by craig04; 04-07-2017 at 03:12 PM.

  11. #11
    Registered User
    Join Date
    10-30-2009
    Location
    sacramento, ca
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: formula to find starting position and count numbers in a string

    Quote Originally Posted by FDibbins View Post
    what would your expected outcome be?
    106300 7/14-7/15/16
    or
    106300
    or something else?
    106300, or 2 & 6 so I can plug it into a mid formula.
    Last edited by craig04; 04-07-2017 at 03:13 PM.

  12. #12
    Registered User
    Join Date
    10-30-2009
    Location
    sacramento, ca
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: formula to find starting position and count numbers in a string

    Quote Originally Posted by sandy666 View Post
    or use result of the first formula (in this case: 2): =SEARCH(" ",A1,2)-2 or =SEARCH(" ",A1,B1)-B1 where B1=result of the first formula
    What if the first character after the number I'm searching for isn't a space?
    Last edited by craig04; 04-07-2017 at 03:13 PM.

  13. #13
    Registered User
    Join Date
    10-30-2009
    Location
    sacramento, ca
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: formula to find starting position and count numbers in a string

    Quote Originally Posted by bebo021999 View Post
    Length:
    =LEN(MAX(IFERROR(MID(A1,MIN(IFERROR(SEARCH(ROW($1:$10)-1,A1),"")),ROW(INDIRECT("1:"&LEN(A1))))+0,"")))
    This was perfect.

  14. #14
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,199

    Re: formula to find starting position and count numbers in a string

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Find the position of the first nr in a string
    By Jacob2010 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-08-2014, 01:52 PM
  2. Formula to count unique numbers in a string
    By ScottBeatty in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-15-2014, 02:09 PM
  3. Replies: 4
    Last Post: 11-30-2010, 05:14 PM
  4. [SOLVED] find nth position of a string
    By TUNGANA KURMA RAJU in forum Excel General
    Replies: 6
    Last Post: 10-18-2005, 09:05 AM
  5. find position of a number in a string
    By fullers80 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-06-2005, 01:05 PM
  6. find position of a number in a string
    By fullers80 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  7. Finding the Relative Position of Numbers within a String
    By ExcelTip in forum Tips and Tutorials
    Replies: 0
    Last Post: 08-23-2005, 04:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1