+ Reply to Thread
Results 1 to 11 of 11

Help pulling unknown amount of data from a cell containing text, into an array

  1. #1
    Registered User
    Join Date
    02-11-2020
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2016
    Posts
    8

    Help pulling unknown amount of data from a cell containing text, into an array

    As an example, Given the table below, without using any helper columns, is there a way I can pull and sum the values from the second column?

    Ideally, I'd like a formula that produces an array of the substrings that can then be manipulated as needed. The items will always be separated by ", ", but there could be any number of them, although a moderate cap on the number of items would be fine if needed.

    Item1 1, 3, 5, 6
    Item2 1, 2, 3
    Item3 2, 45, 89

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

    Re: Help pulling unknown amount of data from a cell containing text, into an array

    For you sum (the argument to the SUMPRODUCT function would be your array producer)...
    Formula: copy to clipboard
    Please Login or Register  to view this content.

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

    Re: Help pulling unknown amount of data from a cell containing text, into an array

    Hi nott0m,

    I found a little bit of magic in Excel a few weeks ago. I was researching the "Evaluate()" function in VBA. It turns out you can put it in a Named Range formula and it will work there too!! I was completely shocked.
    So to do your problem, you don't need any VBA or SumProduct formula simply look at the Named Range formula. You will need to put "=Eval" to the cell to the right of the one with the numbers in it, that are comma separated. This will stump most Excel Guru. Evaluate in Named Range Add.xlsm Click on the underline name to the left to download or open my example file.
    We'll see if Rick has ever seen this when he reads my answer. Rick?
    Last edited by MarvinP; 03-25-2020 at 07:40 PM.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

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

    Re: Help pulling unknown amount of data from a cell containing text, into an array

    I have seen that before... it's a throwback to the old Excel4Macro days if I am not mistaken. However, it does not matter that you did not stump me since I am not rated as an "Excel Guru" on this forum (I am not even rated as an "Excel Expert"... I have more than enough Reputation Points, but am still short by more than 300 postings in order to earn that designation as of now).

    As to the OP's request... after seeing your formula, I realize that I misread the OP's request. When I read this... "is there a way I can pull and sum the values from the second column"... I thought he meant the second item in each cell (and that is what my formula does), but now I realize the OP meant the second column in his "table".

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

    Re: Help pulling unknown amount of data from a cell containing text, into an array

    Being a Guru and $5 will get you a cup of coffee. I sometimes tell people I'm an Excel Guru and they immediately change the subject or turn to talk to someone else.

    I think we vote the Guru's in now so you should be nice to everyone. Don't stop answering questions as I keep learning from your VBA. Hang out here more and get more karma by paying it forward. That is what we all are really working on. It is still fun to learn new stuff about Excel.

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

    Re: Help pulling unknown amount of data from a cell containing text, into an array

    Quote Originally Posted by MarvinP View Post
    Don't stop answering questions as I keep learning from your VBA.
    What an incredibly kind comment for you to make... thank you so much.

  7. #7
    Registered User
    Join Date
    02-11-2020
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2016
    Posts
    8

    Re: Help pulling unknown amount of data from a cell containing text, into an array

    "is there a way I can pull and sum the values from the second column"... I thought he meant the second item in each cell (and that is what my formula does),
    Yeah, I'm sorry I wasn't more clear. Essentially I was looking for would be a formula in column C that gives: 15, 6, 136

  8. #8
    Registered User
    Join Date
    02-11-2020
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2016
    Posts
    8

    Re: Help pulling unknown amount of data from a cell containing text, into an array

    OK, this seems like utter black magic. I'll need to dig into this formula to see how it actually works.

    Thanks!

  9. #9
    Registered User
    Join Date
    02-11-2020
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2016
    Posts
    8

    Re: Help pulling unknown amount of data from a cell containing text, into an array

    OK, so as a follow up.

    Instead of simply pulling numbers, I now want to pull text and use that to lookup the numbers in a table.

    Item Number
    Item1 Num1, Num2
    Item2 Num1, Num2, Num3
    Item3 Num2, Num3

    Number Value
    Num1 5
    Num2 10
    Num3 7

    I tried using the same concept as your example with Range "Eval2" set as
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Where B2 is the second column of the first table, and GetNumbers is the 2nd table.
    The problem is that it seems to only return the first value.

    If I put the argument of the EVALUATE function in a cell, and then paste that result as value and add an equal sign, it seems to work.

    I'm guessing the EVALUATE function doesn't like arrays? Do you have any thoughts?
    Last edited by nott0m; 03-26-2020 at 11:23 AM. Reason: typo

  10. #10
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,885

    Re: Help pulling unknown amount of data from a cell containing text, into an array

    Do you mean that you want something like... below?
    Item Number SUM
    Item1 Num1, Num2 15
    Item2 Num1, Num2, Num3 22
    Item3 Num2, Num3 17

    Assuming this table starts at A1 and the lookup table is in F1:G4

    Something like below.
    In C2:
    =SUMPRODUCT(ISNUMBER(SEARCH($F$2:$F$4,B2))*($G$2:$G$4))

    Copy down.

    EDIT: If you wanted to sum "1, 3, 5, 6" like in your initial post. Another approach is to use FILTERXML() to generate array.

    Ex: =SUM(FILTERXML("<a><b>"&SUBSTITUTE(B2,", ","</b><b>")&"</b></a>","//b"))

    0.JPG
    Last edited by CK76; 03-26-2020 at 04:14 PM.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  11. #11
    Registered User
    Join Date
    02-11-2020
    Location
    Charlotte, NC
    MS-Off Ver
    Excel 2016
    Posts
    8

    Re: Help pulling unknown amount of data from a cell containing text, into an array

    The first one is perfect! Thanks.

    The second one is also great to know and is actually the kind of thing I was kind of expecting originally. I look forward to playing around with the XML stuff a bit.

+ 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. New to macros create report with unknown amount of data
    By airedale360 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-13-2016, 03:20 PM
  2. Pulling row data by cell text
    By tanelli80 in forum Outlook Formatting & Functions
    Replies: 1
    Last Post: 09-17-2013, 03:32 PM
  3. Replies: 2
    Last Post: 07-31-2013, 05:57 PM
  4. Pulling text data and dollar amount data from same cell
    By micadeli in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-25-2013, 11:21 AM
  5. VBA Copying unknown amount of rows
    By Mase123y in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-17-2009, 08:56 AM
  6. Creating a Graph with an unknown amount of data
    By pink in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-19-2009, 04:47 PM
  7. Pulling Data from text in a cell
    By Scomar in forum Excel General
    Replies: 1
    Last Post: 11-09-2007, 03:06 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