boodschappenlijstje uitgaven optellen

littlepete

Well-known Member
Joined
Mar 26, 2015
Messages
507
Office Version
  1. 365
Platform
  1. Windows
dag allemaal :)
ik probeer uit een string (boodschappenlijstje) met een formule de bedragen te halen en op te tellen...
met een matrix lukt niet omdat het samengevoegde cellen zijn...
hoe kan ik uit (bv.) cel AG5 " water 0,75 melk 1,25 chocolade 3,50 brood 1,45 "
het totaal in cel AG8 zetten? (=> 6,95)
vanzelfsprekend kan het aantal items verschillen, wel altijd spaties tussen item en bedrag...
mooie dag nog !!!
 
I started over with a fresh idea. I assume all numbers are separated from surrounding text by a space ( ) or a comma space (, ) or a semicolon space (; ). So three substitutions are made to prepare the text string for splitting. We replace all spaces with "|" to create a new text string. Then in the newly created text string, we replace all occurrences of ",|" and ";|" with "|" to clean up the "," and ";" associated with spaces. These steps convert this string:
List: milk 5, bread 3.32, dark choc 4.45; cheese 6.89 eggs 4 new car 20,000.99
to this:
List:|milk|5||bread|3.32|dark|choc|4.45|cheese|6.89|eggs|4|new|car|20,000.99
Then we split the text string at the "|" characters to give this array:
{"List:","milk","5","","bread","3.32","dark","choc","4.45","cheese","6.89","eggs","4","new","car","20,000.99"}
And as before, we try to multiply each of these array elements by 1. If the element looks like a number, it will be converted from text to a true number. And if the array element is interpreted as text only, the multiplication *1 will produce an error, and we replace the error with a blank, leaving this array:
{"","",5,"","",3.32,"","",4.45,"",6.89,"",4,"","",20000.99}
...an array of blanks and numbers. We can sum this to get the final answer (the blanks are ignored).

I like this approach better because it leaves . and , in the text string if those characters are part of the number. And I'm assuming that whether you use a number convention like 1,234.56 or 1.234,56 for the same value, the number should be interpreted correctly according to the local settings.
MrExcel_20240311.xlsx
AB
1List: milk 5, bread 3.32, dark choc 4.45; cheese 6.89 eggs 4 new car 20,000.9920024.65
2List: milk 5, bread 3.32 dark choc 4.45; cheese 6.89 eggs 423.66
Sheet6
Cell Formulas
RangeFormula
B1:B2B1=SUM(IFERROR(TEXTSPLIT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1," ","|"),",|","|"),";|","|"),"|")*1,""))

Excel Formula:
=SOM(ALS.FOUT(TEKST.SPLITSEN(SUBSTITUEREN(SUBSTITUEREN(SUBSTITUEREN(A1;" ";"|");",|";"|");";|";"|");"|")*1;""))
 
Upvote 1
Solution

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I started over with a fresh idea. I assume all numbers are separated from surrounding text by a space ( ) or a comma space (, ) or a semicolon space (; ). So three substitutions are made to prepare the text string for splitting. We replace all spaces with "|" to create a new text string. Then in the newly created text string, we replace all occurrences of ",|" and ";|" with "|" to clean up the "," and ";" associated with spaces. These steps convert this string:
List: milk 5, bread 3.32, dark choc 4.45; cheese 6.89 eggs 4 new car 20,000.99
to this:
List:|milk|5||bread|3.32|dark|choc|4.45|cheese|6.89|eggs|4|new|car|20,000.99
Then we split the text string at the "|" characters to give this array:
{"List:","milk","5","","bread","3.32","dark","choc","4.45","cheese","6.89","eggs","4","new","car","20,000.99"}
And as before, we try to multiply each of these array elements by 1. If the element looks like a number, it will be converted from text to a true number. And if the array element is interpreted as text only, the multiplication *1 will produce an error, and we replace the error with a blank, leaving this array:
{"","",5,"","",3.32,"","",4.45,"",6.89,"",4,"","",20000.99}
...an array of blanks and numbers. We can sum this to get the final answer (the blanks are ignored).

I like this approach better because it leaves . and , in the text string if those characters are part of the number. And I'm assuming that whether you use a number convention like 1,234.56 or 1.234,56 for the same value, the number should be interpreted correctly according to the local settings.
MrExcel_20240311.xlsx
AB
1List: milk 5, bread 3.32, dark choc 4.45; cheese 6.89 eggs 4 new car 20,000.9920024.65
2List: milk 5, bread 3.32 dark choc 4.45; cheese 6.89 eggs 423.66
Sheet6
Cell Formulas
RangeFormula
B1:B2B1=SUM(IFERROR(TEXTSPLIT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1," ","|"),",|","|"),";|","|"),"|")*1,""))

Excel Formula:
=SOM(ALS.FOUT(TEKST.SPLITSEN(SUBSTITUEREN(SUBSTITUEREN(SUBSTITUEREN(A1;" ";"|");",|";"|");";|";"|");"|")*1;""))
so there we are at the end of our search :) thank you so much for helping me through this !!! i really appreciate it !!! have a nice day !!!
 
Upvote 0
Thank you...and you are welcome. I'm happy to hear that it is working.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,195
Members
453,021
Latest member
pingpong7117

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