View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Harlan Grove[_2_] Harlan Grove[_2_] is offline
external usenet poster
 
Posts: 1,231
Default add multiple numbers in one cell with those numbers remainingvisi

"Rick Rothstein" wrote...
Assuming Harlan's guess is correct (your cells could contain a string like 1
2 4 17 -5 2 0 -7 23 which you want to total up to get 37 as the answer)...
if you are able to use VB code . . .

....

If security isn't an issue, and the OP is (and/or his/her users are)
running Excel 2002 or later versions, then the OP could just use a
defined name calling an XLM function.

If the string of numeric substrings were in cell C5 and the sum of
those substrings were supposed to be in cell D5, with cell D5 the
active cell, define the name SUMNSS as the formula

=EVAL(SUBSTITUTE(TRIM(C5)," ","+"))

then enter the formula =SUMNSS in cell D5. This particular approach
won't trigger macro security warnings when opening the workbook.

If you're going to use VBA udfs, better to make the udfs general
rather than overly particular. In this case, a simple VBA wrapper
around the Excel OM's Evaluate would be the better approach.

Function evaludf(s As String): evaludf = Evaluate(s): End Function

Then try the formula

=evaludf(SUBSTITUTE(TRIM(C5)," ","+"))