INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • 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

Engineering spreadsheets

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

Task 1:
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)
.

Task 2:
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.
Download another excellent free excel add-in from http://www.excelcalcs.com/index.php

Back to -Engineering spreadsheets FAQ Index
Back to -Engineering spreadsheets Forum

My Archive


Resources


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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close