+ Reply to Thread
Results 1 to 6 of 6

Explanation Needed - Extracting Numbers from a String

  1. #1
    Registered User
    Join Date
    04-15-2018
    Location
    Mexicali, Baja California, Mexico
    MS-Off Ver
    2010 & 2016
    Posts
    18

    Question Explanation Needed - Extracting Numbers from a String

    Good day

    I came across a formula that can extract numbers from a mixed string on ExtendOffice.

    https://www.extendoffice.com/documen...om-string.html

    =SUMPRODUCT(MID(0&A5, LARGE(INDEX(ISNUMBER(--MID(A5, ROW(INDIRECT("1:"&LEN(A5))), 1)) * ROW(INDIRECT("1:"&LEN(A5))), 0), ROW(INDIRECT("1:"&LEN(A5))))+1, 1) * 10^ROW(INDIRECT("1:"&LEN(A5)))/10)

    Although the formula works, I can't make heads or tails of how it works.

    If anyone can shed a little light on this I would really appreciate it.

    Thanks

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Explanation Needed - Extracting Numbers from a String

    That is quite an impressive formula. I would never have thought of that in a million years.

    SUMPRODUCT acts as a way to iterate through ranges and compute the product of corresponding elements in the ranges. For example, if you use a formula like this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    the result is A1*B1 + A2*B2 + A3*B3.

    In this case, the range is a series of rows, starting at row 1 and continuing to the row that is identified as the number of characters in the string in A5.
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    The tricky part here is that we don't really care about rows, but we care about the row numbers of those rows--it's a clever way to force SUMPRODUCT to iterate through every character in A5. For each character, if it is a digit (ISNUMBER), it multiplies that digit times the power of 10 corresponding to its position, then sums all those products up. I haven't quite sorted out how it determines the power of 10 to use, but that is the principle in play here.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    04-15-2018
    Location
    Mexicali, Baja California, Mexico
    MS-Off Ver
    2010 & 2016
    Posts
    18

    Re: Explanation Needed - Extracting Numbers from a String

    Attachment 657286

    A lot of that makes sense but this was still my face while I was reading it.

    Thanks for taking the time to respond.

  4. #4
    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: Explanation Needed - Extracting Numbers from a String

    @ DavidFC

    It has always been my understanding that this formula was created by Harlan Grove several years ago.

    This was like seeing an old friend again. So thanks for posting. Like you I (self taught) recall spending many happy hours taking this apart and putting it back together in various ways so I could learn array formulas. I nearly wore out the F9 key and Evaluate Formula (Fx) doing so. LOL

    So keep "plugging away". The time spent in understanding this one is well worth the effort.
    Dave

  5. #5
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Explanation Needed - Extracting Numbers from a String

    First, I would point out that the formula posted in Message #1 does more than the website that was linked to shows. That formula will return all digits in a cell; for example for this...

    ABC1DE23FGH456

    it will return this...

    123456

    As for the OP's search, if there is always a space after the number being searched for (as in the examples at the website you provided a link for), then this shorter normally-entered formula could be used...
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by Rick Rothstein; 01-10-2020 at 05:11 PM.

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,410

    Re: Explanation Needed - Extracting Numbers from a String

    Quote Originally Posted by Rick Rothstein View Post
    As for the OP's search, if there is always a space after the number being searched for...
    If there is not always going to be a space after the number, then this shorter array-entered** formula could be used...
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    ** Commit this formula using CTRL+SHIFT+ENTER and not just Enter by itself

+ 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. RE: Extracting Certain Numbers from a Text String Containing Several Numbers
    By EduardStoo in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 09-04-2018, 07:00 PM
  2. Extracting Numbers Out of String
    By manav1103 in forum Excel Formulas & Functions
    Replies: 22
    Last Post: 05-18-2016, 08:39 PM
  3. Extracting numbers from a String?
    By lolgiggleman in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 02-12-2014, 06:16 AM
  4. [SOLVED] extracting numbers from a string of text and numbers
    By ScottLor in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-05-2013, 04:47 PM
  5. Excel 2007 : Extracting Numbers from A String
    By pxoxyx in forum Excel General
    Replies: 6
    Last Post: 04-28-2010, 01:43 AM
  6. Extracting Numbers a from String
    By ratcat in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-25-2009, 11:13 AM
  7. [SOLVED] extracting numbers from string
    By Chris Dowell via OfficeKB.com in forum Excel General
    Replies: 1
    Last Post: 01-12-2005, 06:06 PM

Tags for this Thread

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