View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
PCLIVE PCLIVE is offline
external usenet poster
 
Posts: 1,311
Default Add cell "50+55+50+50" to give answer 205

You're welcome. I credit Tom Hutchins for the code. It may or may not be
his...but I saw it in one of his posts.

Great stuff.

--

"shyboy2k" wrote in message
...
Hello Paul,

This worked a treat once I allowed the MACRO to work on the spread sheet,
thnx 4 ur help

shyboy2k

"PCLIVE" wrote:

I've seen this request before and thought it was an interesting idea.

Let's say you have the following typed into A1:

4+5

Now you'd like to have the result automatically displayed in another
cell.
The result for this equation, of course, is 9. However, if we don't know
what the equation will be, yet we still want the result automatically
displayed in another cell, then well need to use a UDF (User Defined
Function).
This is done through VBA.
-Press Alt+F11 to open the VB Editor.
Past the following code into a Module.

Function RetVal(Target As Range) As Variant
Dim str As String
'Target must be a single cell
If Target.Count 1 Then
RetVal = vbNullString
Exit Function
End If
'This section removes double quotes, if any.
str$ = Replace(Target.Value, """", vbNullString)
'Evaluate the cell entry.
RetVal = Evaluate("=" & str$)
End Function

Now you can use the following formula in any cell to return the desired
calculation of the equation entered in A1.

=RetVal(A1)


HTH,
Paul

--

"shyboy2k" wrote in message
...
I have a cell where I need to keep the amounts separate to show
workings
out, but I need this to be then added up in a sum, is there a way to do
this
as at present I have to manual work this out and enter in another cell
toget
the answer and this leaves too much room for error.