+ Reply to Thread
Results 1 to 8 of 8

Extract number from text string

  1. #1
    Registered User
    Join Date
    03-31-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    84

    Extract number from text string

    Hi all

    Stumped by this one. I need to extract the 'amount' number from the text strings below. The format varies but there is consistency in that the number i need always follows:

    "amount":"

    here's a sample of the text string variance i'm working with:

    {"amount":"100.0","currency":"sek","customerId":""}
    {"currency":"EUR","customerId":"","amount":"5.0"}
    {"currency":"GBP","amount":"20.0","customerId":""}
    {"currency":"RON","amount":"50.0","customerId":""}
    {"currency":"SEK","customerId":"","amount":"800.0"}
    {"customerId":"","currency":"GBP","amount":"8.0"}
    {"customerId":"","currency":"SEK","amount":"1000.0"}
    {"customerId":"","currency":"SEK","amount":"300.0"}
    {"customerId":"106513976","currency":"DKK","amount":"150.0"}
    {"customerId":"3111","currency":"SEK","amount":"100.0"}

    However, as you can see the number is not fixed digit length nor consistent position within the text string.

    Help appreciated.

  2. #2
    Forum Contributor
    Join Date
    01-05-2017
    Location
    New York
    MS-Off Ver
    Office 2016
    Posts
    206

    Re: Extract number from text string

    Assuming text string is in E2:

    =LEFT(MID(E2,MIN(FIND({0,1,2,3,4,5,6,7,8,9},E2&"0123456789")),25),FIND(CHAR(34),MID(E2,MIN(FIND({0,1,2,3,4,5,6,7,8,9},E2&"0123456789")),25))-1)

    Does this work for you?

  3. #3
    Registered User
    Join Date
    03-31-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Extract number from text string

    Close! It works fine except the two last lines in my example i.e. the text strings that also contain a 'CustomerId'. In those instances the formula outputs the customer iD, not the amount.

    If it makes things easier, i'm happy to use helper columns

    cheers

  4. #4
    Registered User
    Join Date
    03-31-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Extract number from text string

    Close! It works fine except the two last lines in my example i.e. the text strings that also contain a 'CustomerId'. In those instances the formula outputs the customer iD, not the amount.

    If it makes things easier, i'm happy to use helper columns

    cheers

  5. #5
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Extract number from text string

    This works on the posted sample data...

    Data Range
    A
    B
    1
    {"amount":"100.0","currency":"sek","customerId":""}
    100
    2
    {"currency":"EUR","customerId":"","amount":"5.0"}
    5
    3
    {"currency":"GBP","amount":"20.0","customerId":""}
    20
    4
    {"currency":"RON","amount":"50.0","customerId":""}
    50
    5
    {"currency":"SEK","customerId":"","amount":"800.0"}
    800
    6
    {"customerId":"","currency":"GBP","amount":"8.0"}
    8
    7
    {"customerId":"","currency":"SEK","amount":"1000.0"}
    1000
    8
    {"customerId":"","currency":"SEK","amount":"300.0"}
    300
    9
    {"customerId":"106513976","currency":"DKK","amount":"150.0"}
    150
    10
    {"customerId":"3111","currency":"SEK","amount":"100.0"}
    100


    This formula entered in B1 and copied down:

    =LOOKUP(1E100,--MID(A1,SEARCH("amount",A1)+9,{1,2,3,4,5,6,7,8,9}))
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Extract number from text string

    Try this

    =TRIM(LEFT(SUBSTITUTE(MID(A1,FIND("amount",A1)+9,40),CHAR(34),REPT(" ",10)),10))
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  7. #7
    Registered User
    Join Date
    03-31-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    84

    Re: Extract number from text string

    Marvin and Tony,

    These both work perfectly. Thanks ever so much

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Extract number from text string

    You're welcome. Thanks for the feedback!

+ 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. Extract just a phone number from a string of text
    By oneblondebrow in forum Excel General
    Replies: 2
    Last Post: 11-09-2016, 10:49 AM
  2. Need to extract number from Text String
    By EricJonke in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-29-2014, 11:16 AM
  3. Extract the first Number from a Text String
    By ARGK in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 12-23-2013, 07:36 AM
  4. [SOLVED] How to Extract A Number from String if Text within the String Equals XYZ
    By tyrsfury in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-15-2012, 03:30 PM
  5. How do I extract number from text string using macro?
    By Lewis2010 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-12-2011, 04:09 AM
  6. Extract number from text string
    By jjjjj55555 in forum Excel General
    Replies: 2
    Last Post: 04-04-2007, 04:38 PM
  7. Extract a number from a text string?
    By Brian in forum Excel General
    Replies: 8
    Last Post: 01-09-2006, 05:20 PM

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