Calculation from text string

matthew.armitage

Board Regular
Joined
Nov 23, 2009
Messages
72
Hi All

I have got a web report that exports to a text string with the quantity and product. Its always in the same format, starts with "Selection:" and the the "quantity" "x" "product" and then comma. A couple of examples are below:

Selection: 1 x Rose ,1 x Pistachio ,2 x Coffee ,2 x Lemon ,2 x Chocolate ,1 x Nutella ,1 x Raspberry ,1 x Chocolate Mint ,1 x Vanilla ,1 x Pumpkin Spice ,2 x Salted Caramel ,1 x Earl Grey ,1 x Strawberries & Cream ,1 x Chocolate Chilli Mango
Selection: 1 x Pumpkin Spice ,2 x Salted Caramel ,1 x Strawberries & Cream ,1 x Raspberry ,1 x Nutella
Selection: 3 x Pistachio ,1 x Vanilla ,1 x Chocolate ,1 x Rose

What is the best way to get a grand total for each type for the entire list.

I can do it do as a one off excerise using text to colums but takes ages, so would like to automate so I can paste the report into my file and sum automatically.

Thanks

Matt
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Can you upload your data using XL2BB tools or a screenshot with expected results? Do you accept a Power Query solution?
 
Upvote 0
In addition to what @shaowu459 had asked (above), if your data is in A1 and down, then try this formula:
Excel Formula:
=SUM(--SUBSTITUTE(MID(A1,FIND("#",SUBSTITUTE(A1,"x","#",ROW(INDIRECT("1:" & LEN(A1)-LEN(SUBSTITUTE(A1,"x",""))))))-3,3),",",""))
You need to confirm it using the keys Contr-Shift-Enter, non Enter alone

Bye
 
Upvote 0
Do you need the following result?
Book1.xlsx
ABC
1Column1
2Selection: 1 x Rose ,1 x Pistachio ,2 x Coffee ,2 x Lemon ,2 x Chocolate ,1 x Nutella ,1 x Raspberry ,1 x Chocolate Mint ,1 x Vanilla ,1 x Pumpkin Spice ,2 x Salted Caramel ,1 x Earl Grey ,1 x Strawberries & Cream ,1 x Chocolate Chilli Mango
3Selection: 1 x Pumpkin Spice ,2 x Salted Caramel ,1 x Strawberries & Cream ,1 x Raspberry ,1 x Nutella
4Selection: 3 x Pistachio ,1 x Vanilla ,1 x Chocolate ,1 x Rose
5
6Column2Total
7Rose2
8Pistachio4
9Coffee2
10Lemon2
11Chocolate3
12Nutella2
13Raspberry2
14Chocolate Mint1
15Vanilla2
16Pumpkin Spice2
17Salted Caramel4
18Earl Grey1
19Strawberries & Cream2
20Chocolate Chilli Mango1
Sheet15
 
Upvote 0
Data:

Excel challenge.xlsx
A
2Selection: 1 x Rose ,1 x Pistachio ,2 x Coffee ,2 x Lemon ,2 x Chocolate ,1 x Nutella ,1 x Raspberry ,1 x Chocolate Mint ,1 x Vanilla ,1 x Pumpkin Spice ,2 x Salted Caramel ,1 x Earl Grey ,1 x Strawberries & Cream ,1 x Chocolate Chilli Mango
3Selection: 1 x Pumpkin Spice ,2 x Salted Caramel ,1 x Strawberries & Cream ,1 x Raspberry ,1 x Nutella
4Selection: 3 x Pistachio ,1 x Vanilla ,1 x Chocolate ,1 x Rose
Sheet3


Expected results:

Excel challenge.xlsx
DE
6Rose1
7Pumpkin Spice2
8Pistachio4
9Salted Caramel4
10Vanilla2
11Coffee2
12Strawberries & Cream2
13Chocolate3
14Lemon2
15Raspberry2
16Rose1
17Nutella2
18Chocolate Mint1
19Earl Grey1
20Chocolate Chilli Mango1
Sheet3


In terms of power query its not somthing that I have used before, so would prefer to avoid it, but if that is the only way then I will learn how to use it,

Thanks

Matt
 
Upvote 0
Do you need the following result?
Book1.xlsx
ABC
1Column1
2Selection: 1 x Rose ,1 x Pistachio ,2 x Coffee ,2 x Lemon ,2 x Chocolate ,1 x Nutella ,1 x Raspberry ,1 x Chocolate Mint ,1 x Vanilla ,1 x Pumpkin Spice ,2 x Salted Caramel ,1 x Earl Grey ,1 x Strawberries & Cream ,1 x Chocolate Chilli Mango
3Selection: 1 x Pumpkin Spice ,2 x Salted Caramel ,1 x Strawberries & Cream ,1 x Raspberry ,1 x Nutella
4Selection: 3 x Pistachio ,1 x Vanilla ,1 x Chocolate ,1 x Rose
5
6Column2Total
7Rose2
8Pistachio4
9Coffee2
10Lemon2
11Chocolate3
12Nutella2
13Raspberry2
14Chocolate Mint1
15Vanilla2
16Pumpkin Spice2
17Salted Caramel4
18Earl Grey1
19Strawberries & Cream2
20Chocolate Chilli Mango1
Sheet15

Yes!
 
Upvote 0
Data:

Excel challenge.xlsx
A
2Selection: 1 x Rose ,1 x Pistachio ,2 x Coffee ,2 x Lemon ,2 x Chocolate ,1 x Nutella ,1 x Raspberry ,1 x Chocolate Mint ,1 x Vanilla ,1 x Pumpkin Spice ,2 x Salted Caramel ,1 x Earl Grey ,1 x Strawberries & Cream ,1 x Chocolate Chilli Mango
3Selection: 1 x Pumpkin Spice ,2 x Salted Caramel ,1 x Strawberries & Cream ,1 x Raspberry ,1 x Nutella
4Selection: 3 x Pistachio ,1 x Vanilla ,1 x Chocolate ,1 x Rose
Sheet3


Expected results:

Excel challenge.xlsx
DE
6Rose1
7Pumpkin Spice2
8Pistachio4
9Salted Caramel4
10Vanilla2
11Coffee2
12Strawberries & Cream2
13Chocolate3
14Lemon2
15Raspberry2
16Rose1
17Nutella2
18Chocolate Mint1
19Earl Grey1
20Chocolate Chilli Mango1
Sheet3


In terms of power query its not somthing that I have used before, so would prefer to avoid it, but if that is the only way then I will learn how to use it,

Thanks

Matt
Please refer to my post #4, Power Query is a more suitable tool for your case. I will post the code if you need.
By the way, there is a trailing blank after "Rose", so you get two lines of "Rose" in above post.
 
Upvote 0
In addition to what @shaowu459 had asked (above), if your data is in A1 and down, then try this formula:
Excel Formula:
=SUM(--SUBSTITUTE(MID(A1,FIND("#",SUBSTITUTE(A1,"x","#",ROW(INDIRECT("1:" & LEN(A1)-LEN(SUBSTITUTE(A1,"x",""))))))-3,3),",",""))
You need to confirm it using the keys Contr-Shift-Enter, non Enter alone

Bye

This seems to be adding the numbers toghter on each row, rather than a caclaution to sum the total for each flavour for the entire list

Thanks
 
Upvote 0
This seems to be adding the numbers toghter on each row, rather than a caclaution to sum the total for each flavour for the entire list

Thanks
I understood the question the wrong way, let's see were the answer will arrive
 
Upvote 0
Please refer to my post #4, Power Query is a more suitable tool for your case. I will post the code if you need.
By the way, there is a trailing blank after "Rose", so you get two lines of "Rose" in above post.

Well spotted on Rose

Please can you send me the code and I will do some research on how to use power query, thanks.
 
Upvote 0

Forum statistics

Threads
1,224,833
Messages
6,181,242
Members
453,026
Latest member
cknader

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top