Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 13
Default How to do for this kind of formula?

Suppose Cell: A1 = "1+2+3"
and any method to get its result(6) in Cell A2

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default How to do for this kind of formula?

Copy this UDF to a genral module.

Function EvalCell(RefCell As String)
Application.Volatile
EvalCell = Evaluate(RefCell)
End Function

=EvalCell(A1) in A2 returns 6

First off.........save a backup of your workbook.

If not familiar with VBA and macros, see David McRitchie's site for more on
"getting started".

http://www.mvps.org/dmcritchie/excel/getstarted.htm

In the meantime..........

To create a General Module, hit ALT + F11 to open the Visual Basic Editor.

Hit CRTL + R to open Project Explorer.

Find your workbook/project and select it.

Right-click and InsertModule. Paste the code in there.

Save the workbook and hit ALT + Q to return to Excel window.

Enter the formula in a helper cell as explained above.


Gord Dibben MS Excel MVP



On Mon, 11 Jun 2007 20:00:01 -0700, kelvin
wrote:

Suppose Cell: A1 = "1+2+3"
and any method to get its result(6) in Cell A2


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,651
Default How to do for this kind of formula?

On Mon, 11 Jun 2007 20:00:01 -0700, kelvin
wrote:

Suppose Cell: A1 = "1+2+3"
and any method to get its result(6) in Cell A2


You can use a UDF.

How involved depends on the variety of what might be in A1.

If just quote marks, numbers and operators, then you can use something simple:

<alt-F11 opens the VB Editor.

Ensure your project is highlighted in the project explorer window, then
Insert/Module and paste the code below into the window that opens:

=============================
Function Eval(rg)
Dim str As String
str = Replace(rg.Text, """", "")
Eval = Evaluate(str)
End Function
=============================

A2: =Eval(A1)

However, if there might be characters other than quote marks and the various
operators, then you need to strip them all out:

==========================================

Function Eval(rg)
Dim str As String

'ensure contains only numbers and operators
Dim oRegex As Object
Set oRegex = CreateObject("VBScript.RegExp")

With oRegex
.Global = True
.Pattern = "[^-0-9+/*^\()]"
End With

str = oRegex.Replace(rg.Text, "")
Eval = Evaluate(str)

End Function
=========================

--ron
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to do this kind of sorting? Eric Excel Worksheet Functions 3 December 14th 06 09:56 AM
Is this kind of count possible?... Dan B Excel Worksheet Functions 4 December 11th 06 09:56 PM
Help what kind of formula? Emil0 New Users to Excel 3 February 6th 06 09:10 PM
What kind of Formula?? Mike R Excel Discussion (Misc queries) 0 February 17th 05 04:17 AM
kind of rank Jack Sons Excel Discussion (Misc queries) 6 December 27th 04 12:08 PM


All times are GMT +1. The time now is 05:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"