Sum up numbers in a string of text in a single cell

sjn6900

New Member
Joined
Aug 2, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have some output that is being presented to us in excel (relates to order details - each order in a new cell).

In each cell, i have a string of information that includes things like the following:

<ItemNumber>1</ItemNumber> <Quantity>1</Quantity> <NetWeight>1.412</NetWeight> <GrossWeight>1.412</GrossWeight> <ItemNumber>2</ItemNumber> <Quantity>1</Quantity> <UnitPrice>0</UnitPrice> <NetWeight>1.41</NetWeight> <GrossWeight>1.41</GrossWeight> <ItemNumber>3</ItemNumber> <Quantity>1</Quantity> <NetWeight>0.002</NetWeight> <GrossWeight>0.002</GrossWeight> <ItemNumber>4</ItemNumber> <Quantity>1</Quantity> <NetWeight>0.06</NetWeight> <GrossWeight>0.06</GrossWeight> <ItemNumber>5</ItemNumber> <Quantity>1</Quantity> <NetWeight>0.268</NetWeight> <GrossWeight>0.268

I need a way to be able to search through the text in each cell and sum up all of the numbers shown in the Gross Weight sections. The number of items whose gross weights need to be summed up will be different in each cell. The numbers that need to be summed will always have <GrossWeight> before and </GrossWeight> after.

I can't figure a way to use the usual text functions, so assume some VBA would be the best way to deal with this (way beyond my knowledge i'm afriad!)
Any help would be much appreciated.

thanks.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Welcome to the MrExcel board!

The numbers that need to be summed will always have <GrossWeight> before and </GrossWeight> after.
So the total would not include that last 0.268 in your sample?
.. or is the sample not complete?
 
Upvote 0
it would - i've not completed the sample properly. sorry about that.
 
Upvote 0
See if this works for you.

gifariz.xlsm
AB
1<ItemNumber>1</ItemNumber> <Quantity>1</Quantity> <NetWeight>1.412</NetWeight> <GrossWeight>1.412</GrossWeight> <ItemNumber>2</ItemNumber> <Quantity>1</Quantity> <UnitPrice>0</UnitPrice> <NetWeight>1.41</NetWeight> <GrossWeight>1.41</GrossWeight> <ItemNumber>3</ItemNumber> <Quantity>1</Quantity> <NetWeight>0.002</NetWeight> <GrossWeight>0.002</GrossWeight> <ItemNumber>4</ItemNumber> <Quantity>1</Quantity> <NetWeight>0.06</NetWeight> <GrossWeight>0.06</GrossWeight> <ItemNumber>5</ItemNumber> <Quantity>1</Quantity> <NetWeight>0.268</NetWeight> <GrossWeight>0.268</GrossWeight>3.152
Sheet1
Cell Formulas
RangeFormula
B1B1=SUM(FILTERXML("<p><c>"&SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1&"x",">",""),"<",""),"/",""),"GrossWeight","</c><c>")&"</c></p>","//c"))
 
Upvote 0
Another option
Fluff.xlsm
AB
1
2<ItemNumber>1</ItemNumber> <Quantity>1</Quantity> <NetWeight>1.412</NetWeight> <GrossWeight>1.412</GrossWeight> <ItemNumber>2</ItemNumber> <Quantity>1</Quantity> <UnitPrice>0</UnitPrice> <NetWeight>1.41</NetWeight> <GrossWeight>1.41</GrossWeight> <ItemNumber>3</ItemNumber> <Quantity>1</Quantity> <NetWeight>0.002</NetWeight> <GrossWeight>0.002</GrossWeight> <ItemNumber>4</ItemNumber> <Quantity>1</Quantity> <NetWeight>0.06</NetWeight> <GrossWeight>0.06</GrossWeight> <ItemNumber>5</ItemNumber> <Quantity>1</Quantity> <NetWeight>0.268</NetWeight> <GrossWeight>0.268 </GrossWeight>3.152
Report
Cell Formulas
RangeFormula
B2B2=SUM(FILTERXML("<k>"&A2&"</k>","//GrossWeight"))
 
Upvote 0
Another option
.. just a bit shorter than mine. (y) :biggrin:

Another option if the TEXTSPLIT function is available in your 365 version.

gifariz.xlsm
AB
1<ItemNumber>1</ItemNumber> <Quantity>1</Quantity> <NetWeight>1.412</NetWeight> <GrossWeight>1.412</GrossWeight> <ItemNumber>2</ItemNumber> <Quantity>1</Quantity> <UnitPrice>0</UnitPrice> <NetWeight>1.41</NetWeight> <GrossWeight>1.41</GrossWeight> <ItemNumber>3</ItemNumber> <Quantity>1</Quantity> <NetWeight>0.002</NetWeight> <GrossWeight>0.002</GrossWeight> <ItemNumber>4</ItemNumber> <Quantity>1</Quantity> <NetWeight>0.06</NetWeight> <GrossWeight>0.06</GrossWeight> <ItemNumber>5</ItemNumber> <Quantity>1</Quantity> <NetWeight>0.268</NetWeight> <GrossWeight>0.268</GrossWeight>3.152
Sheet1
Cell Formulas
RangeFormula
B1B1=SUM(IFERROR(TEXTSPLIT(SUBSTITUTE(A1,"/",""),"<GrossWeight>")+0,0))
 
Upvote 0
Hi,

I don't have the textsplit function yet in my O365 release.

the =SUM(FILTERXML("<k>"&A2&"</k>","//GrossWeight")) was perfect.

thanks so much for the quick response.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,341
Members
452,638
Latest member
Oluwabukunmi

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