SOLVED

There's a problem with this formula.

%3CLINGO-SUB%20id%3D%22lingo-sub-2054345%22%20slang%3D%22en-US%22%3EThere's%20a%20problem%20with%20this%20formula.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2054345%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20set%20of%20data%20that%20had%20a%20varying%20series%20of%20numbers%20separated%20by%20commas%20in%20a%20column%20of%20cells%20in%20Excel%202016.%26nbsp%3B%20I%20used%20search%20and%20replace%20to%20change%20the%20commas%20to%20plus%20signs%20and%20then%20concatenated%20an%20equal%20sign%20to%20that%20data%20in%20a%20new%20cell%20in%20an%20attempt%20to%20create%20a%20formula%20that%20added%20together%20the%20numbers%20without%20having%20to%20retype%20everything.%26nbsp%3B%20When%20I%20did%20that%2C%20even%20though%20the%20formula%20is%20simple%20(e.g.%2C%20%3D12%2B987987%2B3452%2B7893)%20and%20appears%20correct%2C%20I%20get%20a%20message%20that%20says%20%22There's%20a%20problem%20with%20this%20formula.%22%26nbsp%3B%20It%20won't%20calculate%20even%20when%20I%20format%20the%20data%20type%20to%20number%20or%20general.%26nbsp%3B%20How%20might%20I%20correct%20this%20error%20and%20get%20the%20formulas%20to%20resolve%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2054345%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2054738%22%20slang%3D%22en-US%22%3ERe%3A%20There's%20a%20problem%20with%20this%20formula.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2054738%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F780339%22%20target%3D%22_blank%22%3E%40wiscy%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlthough%20the%20result%20of%20the%20substitutions%20may%20look%20like%20a%20formula%2C%20it%20is%20in%20fact%20still%20a%20text%20string%20that%20happens%20to%20contain%20many%20digits.%26nbsp%3B%20Options%20include%3C%2FP%3E%3CP%3E1.%20Using%20EVAL2%20from%20Charles%20Williams's%20FastExcel%20library%3C%2FP%3E%3CP%3E2.%20Use%20a%20defined%20name%20containing%20the%20old%20Macro4%20function%20EVALUATE%3C%2FP%3E%3CP%3E3.%20Write%20a%20UDF%20using%20VBA%20to%20access%20its%20EVALUATE%20function%3C%2FP%3E%3CP%3E4.%20Parse%20the%20string%20and%20convert%20each%20value%20into%20a%20number%20using%20the%20VALUE%20function%2C%20then%20sum%20them.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFollowing%20option%202%2C%20write%20a%20formula%26nbsp%3B%3C%2FP%3E%3CP%3E%3D%20%3CSTRONG%3EEVAL%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Ein%20the%20cell%20immediately%20to%20the%20right%20of%20your%20formula.%26nbsp%3B%20Go%20to%20Name%20Manager%20and%20create%20a%20new%20name%20%3CSTRONG%3EEVAL%3C%2FSTRONG%3E%20which%20refers%20to%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3E%3DEVALUATE(Sheet1!D5)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3Ewhere%20D5%20is%20a%20relative%20reference%20to%20your%20cell.%26nbsp%3B%20The%20%22%3D%22%20can%20be%20inserted%20at%20the%20beginning%20of%20the%26nbsp%3B%20string%20but%20the%20formulas%20will%20still%20work%20without%20it.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2054825%22%20slang%3D%22en-US%22%3ERe%3A%20There's%20a%20problem%20with%20this%20formula.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2054825%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3B%20I%20can't%20complete%20creation%20of%20the%20formula%20in%20the%20attached%20image%20because%20I%20get%20the%20error%20message.%26nbsp%3B%20In%20addition%2C%20I%20don't%20see%20Evaluate%20as%20a%20function%20within%20Excel%202016.%26nbsp%3B%20I%20get%20a%20%23NAME!%20error%20creating%20the%20formula%2C%20as%20indicated.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2054957%22%20slang%3D%22en-US%22%3ERe%3A%20There's%20a%20problem%20with%20this%20formula.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2054957%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F780339%22%20target%3D%22_blank%22%3E%40wiscy%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20only%20use%20evaluate%20within%20a%20defined%20name%3B%20it%20does%20not%20work%20on%20the%20grid.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2056808%22%20slang%3D%22en-US%22%3ERe%3A%20There's%20a%20problem%20with%20this%20formula.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2056808%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F675152%22%20target%3D%22_blank%22%3E%40JMB17%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20experimented%20with%20the%20XML%20solution%20using%20modern%20Excel%20365%20functions.%26nbsp%3B%20First%20LET%2C%20which%20allows%20local%20names%20to%20be%20introduced%20in%20order%20to%20remove%20nested%20formulas.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3D%20LET(%0A%20%20%20%20XML%2C%20%22%3CLIST%3E%3CITEM%3E%22%20%26amp%3B%0A%20%20%20%20%20%20%20%20%20SUBSTITUTE(listCosts%2C%22%2C%22%2C%22%3C%2FITEM%3E%3CITEM%3E%22)%20%26amp%3B%0A%20%20%20%20%20%20%20%20%20%22%3C%2FITEM%3E%3C%2FLIST%3E%22%2C%0A%20%20%20%20list%2C%20FILTERXML(XML%2C%22%2F%2Fitem%22)%2C%0A%20%20%20%20SUM(list)%20)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%3CU%3EXML%3C%2FU%3E%20is%20the%20markup%20language%20version%20of%20the%20CSV%20string%2C%20%3CU%3Elist%3C%2FU%3E%20is%20it%20as%20separate%20items%20and%2C%20since%20all%20calculation%20is%20performed%20as%20array%20calculation%20in%20365%2C%20SUM%20will%20do.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20next%20step%20is%20to%20wrap%20the%20LET%20with%20the%20newly%20developed%20LAMBDA%20function%20which%20allows%20a%20user%20to%20pass%20different%20parameters%20to%20the%20same%20function.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3D%20LAMBDA(listCosts%2C%0A%20%20%20LET(%20...%0A%20%20...%20)%0A%20%20%20)(ItemCosts)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3ENaming%20the%20function%20TotalXML%2C%20gives%20a%20final%20form%20for%20the%20function%20call%20of%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3D%20TotalXML(ItemCosts)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EI%20did%20also%20write%20a%20recursive%20Lambda%20function%20TotalCSV%2C%20using%20only%20basic%20text%20handling%20functions%2C%20but%20this%20is%20not%20the%20place%20to%20describe%20the%20solution.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2057127%22%20slang%3D%22en-US%22%3ERe%3A%20There's%20a%20problem%20with%20this%20formula.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2057127%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI'd%20do%20not%20rely%20on%20FILTERXML%20with%20functions%20like%20TEXTSPLIT.%20Try%20to%20split%20text%20like%20%22a%2C%20b%26amp%3Bc%2C%20d%22.%20Ampersand%20is%20not%20the%20only%20symbol%20with%20which%20it%20doesn't%20work%2C%20you%20may%20google%20for%20all%20of%20them.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWith%20LET%2FLAMBDA%20you%20may%20build%20such%20function%20without%20FILTERXML%2C%20and%20it%20will%20be%20more%20reliable.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2057518%22%20slang%3D%22en-US%22%3ERe%3A%20There's%20a%20problem%20with%20this%20formula.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2057518%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20don't%20have%20office%20365%20on%20my%20home%20machine.%20And%2C%20even%20though%20it's%20on%20my%20work%20machine%2C%20not%20only%20are%20we%20in%20the%20slowest%20channel%2C%20but%20the%20IT%20department%20packages%20and%20deploys%20the%20updates%20themselves%2C%20so%20we're%20actually%20months%20behind%20the%20slowest%20channel.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYes%2C%20I%20think%20a%20textsplit%20function%2C%20if%20they've%20released%20one%2C%20would%20be%20better.%20The%20issue%20of%20filterxml%20errors%20due%20to%20special%20characters%20doesn't%20appear%20to%20apply%20based%20on%20the%20OP's%20description%20of%20the%20data.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2057679%22%20slang%3D%22en-US%22%3ERe%3A%20There's%20a%20problem%20with%20this%20formula.%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2057679%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Sergei%3C%2FP%3E%3CP%3EI%20had%20used%20the%20problem%20to%20challenge%20my%20thinking%20using%20the%20newly%20available%20LAMBDA%20functions.%3C%2FP%3E%3CP%3EI%20did%20also%20create%20a%20recursive%20formula%2C%20based%20upon%20a%20rework%20of%20the%20Fibonacci%20recursion%20spreadsheet.%26nbsp%3B%20There%20must%20be%20times%20when%20I%20irritate%20members%20with%20my%20alien%20solutions%20and%20I%20felt%20that%20a%20recursive%20solution%20was%20a%20couple%20of%20steps%20too%20far%20here.%26nbsp%3B%20However%2C%20to%20prove%20it%20exists%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3D%20TotalCSV(ItemCosts)%0A%0Awhere%20TotalCSV%20refers%20to%0A%3D%20LAMBDA(residual%2C%0A%20%20%20%20LET(%0A%20%20%20%20%20%20n%2C%20IFERROR(%20FIND(%22%2C%22%2C%20residual)%2C%201%2BLEN(residual))%2C%0A%20%20%20%20%20%20item%2C%20VALUE(LEFT(residual%2C%20n-1))%2C%0A%20%20%20%20%20%20reduced%2C%20REPLACE(residual%2C%201%2C%20n%2B1%2C%22%22)%2C%0A%20%20%20%20%20%20partialSum%2C%20IF(reduced%26lt%3B%26gt%3B%22%22%2C%20TotalCSV(reduced)%2C%200)%2C%0A%20%20%20%20%20%20partialSum%20%2B%20item%20)%0A%20%20%20%20)(ItemCosts)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EI%20offer%20apologies%20for%20those%20who%20will%20not%20be%20in%20a%20position%20to%20evaluate%20such%20methods%2C%20and%20may%20not%20be%20for%20many%20years.%26nbsp%3B%20We%20seem%20to%20have%20reached%20a%20point%20where%20Excel%20365%2C%20though%20it%20%3CU%3Ecan%3C%2FU%3E%20run%20legacy%20spreadsheet%20solutions%2C%20is%20actually%20an%20utterly%20different%20platform%20which%20supports%20a%20programming%20approach%20to%20solving%20problems.%26nbsp%3B%20When%20and%20whether%20the%20two%20strategies%20will%20ever%20come%20together%20once%20more%2C%20I%20am%20not%20so%20sure.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

I have a set of data that had a varying series of numbers separated by commas in a column of cells in Excel 2016.  I used search and replace to change the commas to plus signs and then concatenated an equal sign to that data in a new cell in an attempt to create a formula that added together the numbers without having to retype everything.  When I did that, even though the formula is simple (e.g., =12+987987+3452+7893) and appears correct, I get a message that says "There's a problem with this formula."  It won't calculate even when I format the data type to number or general.  How might I correct this error and get the formulas to resolve?

12 Replies

@wiscy 

Although the result of the substitutions may look like a formula, it is in fact still a text string that happens to contain many digits.  Options include

1. Using EVAL2 from Charles Williams's FastExcel library

2. Use a defined name containing the old Macro4 function EVALUATE

3. Write a UDF using VBA to access its EVALUATE function

4. Parse the string and convert each value into a number using the VALUE function, then sum them.

 

Following option 2, write a formula 

= EVAL

in the cell immediately to the right of your formula.  Go to Name Manager and create a new name EVAL which refers to 

=EVALUATE(Sheet1!D5)

where D5 is a relative reference to your cell.  The "=" can be inserted at the beginning of the  string but the formulas will still work without it.

@Peter Bartholomew  I can't complete creation of the formula in the attached image because I get the error message.  In addition, I don't see Evaluate as a function within Excel 2016.  I get a #NAME! error creating the formula, as indicated.

@wiscy 

You can only use evaluate within a defined name; it does not work on the grid.

best response confirmed by wiscy (Occasional Contributor)
Solution
One other way I believe you can do it. Assuming your comma delimited text string of numbers is in cell A1:

=SUMPRODUCT(FILTERXML("<L><I>"&SUBSTITUTE(A1,",","</I><I>")&"</I></L>","//I"))

@JMB17  This formula worked perfectly.  Thanks!

Quite welcome. Glad to hear it worked for you.

@JMB17 

I experimented with the XML solution using modern Excel 365 functions.  First LET, which allows local names to be introduced in order to remove nested formulas.

= LET(
    XML, "<list><item>" &
         SUBSTITUTE(listCosts,",","</item><item>") &
         "</item></list>",
    list, FILTERXML(XML,"//item"),
    SUM(list) )

XML is the markup language version of the CSV string, list is it as separate items and, since all calculation is performed as array calculation in 365, SUM will do.

 

The next step is to wrap the LET with the newly developed LAMBDA function which allows a user to pass different parameters to the same function.

= LAMBDA(listCosts,
   LET( ...
  ... )
   )(ItemCosts)

Naming the function TotalXML, gives a final form for the function call of

= TotalXML(ItemCosts)

I did also write a recursive Lambda function TotalCSV, using only basic text handling functions, but this is not the place to describe the solution.

 

@Peter Bartholomew 

I'd do not rely on FILTERXML with functions like TEXTSPLIT. Try to split text like "a, b&c, d". Ampersand is not the only symbol with which it doesn't work, you may google for all of them.

 

With LET/LAMBDA you may build such function without FILTERXML, and it will be more reliable. 

 

@Peter Bartholomew 

 

I don't have office 365 on my home machine. And, even though it's on my work machine, not only are we in the slowest channel, but the IT department packages and deploys the updates themselves, so we're actually months behind the slowest channel.

 

Yes, I think a textsplit function, if they've released one, would be better. The issue of filterxml errors due to special characters doesn't appear to apply based on the OP's description of the data.

 

 

 

@Sergei Baklan 

Hi Sergei

I had used the problem to challenge my thinking using the newly available LAMBDA functions.

I did also create a recursive formula, based upon a rework of the Fibonacci recursion spreadsheet.  There must be times when I irritate members with my alien solutions and I felt that a recursive solution was a couple of steps too far here.  However, to prove it exists

= TotalCSV(ItemCosts)

where TotalCSV refers to
= LAMBDA(residual,
    LET(
      n, IFERROR( FIND(",", residual), 1+LEN(residual)),
      item, VALUE(LEFT(residual, n-1)),
      reduced, REPLACE(residual, 1, n+1,""),
      partialSum, IF(reduced<>"", TotalCSV(reduced), 0),
      partialSum + item )
    )(ItemCosts)

I offer apologies for those who will not be in a position to evaluate such methods, and may not be for many years.  We seem to have reached a point where Excel 365, though it can run legacy spreadsheet solutions, is actually an utterly different platform which supports a programming approach to solving problems.  When and whether the two strategies will ever come together once more, I am not so sure.

@JMB17 

I have nothing against FILTERXML in this concrete case, I'd only don't use it as TEXTSPLIT in general.

@Peter Bartholomew , will check, thank you. But I'd generalize using any text as delimiter, e.g. like "=@="