×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

#### Jobs

How to display formulas in the worksheet dynamically by yakpol
Posted: 27 Jun 01 (Edited 14 Jan 08)

You want the formula behind a certain cell value to be constantly displayed in the other cell.

To do so, write a custom function in VBA as follows:

#### CODE

Public Function DisplayFormula(rng As Range) As String
Displayformula = rng.Formula
End Function
Place this function in the worksheet using the interested cell as an argument

#### CODE

=DisplayFormula(A1)
.

You want to write a formula as a label, being visible and editable, and to display the result of this formula in the other cell.

Go back to VBA and write another short function:

#### CODE

Public Function EvaluateFormula(rng As Range) As Double
EvaluateFormula = Application.Evaluate("=" & rng.FORMULA)
End Function
Insert this function into the spreadsheet using cell with the formula as an argument. Note that the function above requires no '=' sign before or after the formula. To relax the syntax modify function in the following way:

#### CODE

Public Function EvaluateFormula(rng As Range) As Double
Dim str As String
str = Trim(rng.FORMULA)
If Left(str, 1) <> "=" Then str = "=" & str
If Right(str, 1) = "=" Then str = Left(str, Len(str) - 1)
EvaluateFormula = Application.Evaluate(str)
End Function
Now you can type the formula you want to evaluate with heading and trailing '=' sign, like:

#### CODE

'= A1+A2 =
Display values behind formula.
Download excellent VBA function disfor() from http://www.geocities.com/SiliconValley/Hills/1829/VBA/index.html The formula will look like actual handwriting, e.g. (5+6.3)/3.

Displaying cell formulae as two-dimensional mathematical equations.

Back to -Engineering spreadsheets FAQ Index

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!