Share via

Excel - adding numbers within a text string

Anonymous
2016-12-05T18:07:01+00:00

I would like to add numbers that are within a text string but I need to only add the number to the left of matching criteria.  My data looks like this  

Column H:  

1 Meal

1 Meal, 1 Extra

1 Meal, 1 Piz

1 Piz, 2 Piz

1 Extra

1 Extra, 1 Meal

I want to sum each type of menu choice

Extras: 3

Meals: 4

Piz: 4

Thank you in advance.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2016-12-06T13:44:30+00:00

A solution using Excel formulas, though a long formula, and valid for upto 2 occurrences of a type in one cell. Refer below image:

Enter below formula as an array formula (CTRL+SHIFT+ENTER) in cell D2 and copy down:

=SUM(IF(ISNUMBER(VALUE(IFERROR(TRIM(RIGHT(SUBSTITUTE(TRIM(LEFT(SUBSTITUTE($A$2:$A$10,C2,REPT(" ",255)),255)),",",REPT(" ",255)),255)),0))),VALUE(IFERROR(TRIM(RIGHT(SUBSTITUTE(TRIM(LEFT(SUBSTITUTE($A$2:$A$10,C2,REPT(" ",255)),255)),",",REPT(" ",255)),255)),0))))+SUM(IF(ISNUMBER(VALUE(IFERROR(TRIM(RIGHT(SUBSTITUTE(TRIM(LEFT(SUBSTITUTE(SUBSTITUTE($A$2:$A$10,C2,"?",1),C2,REPT(" ",255)),255)),",",REPT(" ",255)),255)),0))),VALUE(IFERROR(TRIM(RIGHT(SUBSTITUTE(TRIM(LEFT(SUBSTITUTE(SUBSTITUTE($A$2:$A$10,C2,"?",1),C2,REPT(" ",255)),255)),",",REPT(" ",255)),255)),0))))

Regards,

Amit Tandon

Was this answer helpful?

0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Anonymous
    2016-12-06T14:19:24+00:00

    Amit, it works perfectly!  That is exactly what we needed.  Thank you!!

     I really appreciate the help from such brilliant people.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2016-12-05T21:52:11+00:00

    How many items may end up in the same cell? Your sample shows 2. Could it be more?

    Is there any way you could get the data from the web in a different format?

    In any case, you need to perform some data cleansing before you can work with the numbers buried in the text. There are many possible approaches. It depends what you are comfortable with. Would you be fine with a VBA solution?

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2016-12-05T21:27:53+00:00

    Thank you for your response.  I am getting the data from a website form where multiple selections can be chosen so that is the reason for the difficult format.  If I modify the website form so that quantity and item have to be filled in, it will be more cumbersome for parents.  Is that the only way I can get a sum of each item?  

    Thanks much!

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2016-12-05T20:15:53+00:00

    Hello,

    with a data entry format like that, it will be either immensely complex or even impossible to produce the result you describe. There are a few ground rules for spreadsheet design that, when followed, will make things a lot easier.

    If you enter the data into a simple table, one column for the text, one column for the number, and put each text/number combination into its own row, then creating the summary you describe is really easy: Select the data, click Insert > Pivot table. Drag the "Food Type" field to the Rows and the "amount" field to the Values area and you're done.

    Was this answer helpful?

    0 comments No comments