View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default add multiple numbers in one cell with those numbers remaining visi

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)," ","+"))


We can generalize my UDF and save the user from having to remember to pass
that combination of worksheet functions as an argument...

Function Calc(R As Range, Optional Operator As String = "+") As Double
Calc = Evaluate(Replace(WorksheetFunction.Trim(R.Value), " ", Operator))
End Function

where the user can now include the operator symbol to place between the
numbers in his/her series. So, for the general reader out there, the UDF can
be used to, say, multiply the values in the string with this function
call...

=Calc(A1,"*")

Just pass the operator symbol into the second argument. Note that the second
argument is optional and, if omitted, defaults to summation, so the OP's
originally requested summation would be performed by doing either this...

=Calc(A1,"+")

or, more simply, this...

=Calc(A1)

--
Rick (MVP - Excel)