• User Defined Function To Show Formulas In A Cell

    Macro Purpose:
    • Function to show the formula in another cell as text.

    Examples of where this function shines:
    • In Excel's View options (Tools|Options|View), you can check a box to show all formulas on the worksheet as formulas, rather than their resulting values. The problem is that this is worksheet level, and sometimes that may not be desireable. This function allows you to show the formulas on the worksheet if you desire.
    • As an example of a practical use for this function, I have used it throughout this site to show what formulas I use in my examples.

    Macro Weakness(es):
    • None identified at this time.

    Versions Tested:
    This function has been tested extensively with Excel 97 through Excel 2010, and shouldn't have an issue in any version of Excel from 97 onwards.

    VBA Code Required:
    • Place the following code in a standard module of the workbook you wish to use it in.
    Code:
    Function showformula(rng As Range)
    'Author          : Ken Puls (www.excelguru.ca)
    'Function Purpose: To show a range's formula in a cell
        If rng.HasArray = True Then
            showformula = "{" & rng.Formula & "}"
        Else
            showformula = rng.Formula
        End If
    End Function
    How to use the code:
    • Enter the formula in a worksheet cell in the format =SHOWFORMULA(Range)
    • The results will show similar to what is below



    The End Result:
    • You can see both formula results and actual formulas on the same page.

    Try it For Yourself!
    A completed file with the formula already in place is ready for you to take for a spin!

  • MVP Logo
  •  Donations

    If you like our website and would like to give something in return, you can make a donation. All donations are gratefully received and go to support the site.


    Select your preferred currency and donation amount, then click the donate button.

  • Recent Forum Posts

    Colo

    How to Rename a File from English to Other Language?

    Yeah, some massive HTML conversion is my line. In other words, most of difficult things can be done with Excel alone like this time. Well done, Excel!...

    Colo Today, 07:36 AM Go to last post
    Ken Puls

    Link a series name to a cell using Excel 2010 VBA

    Hi there,

    I recorded linking the title to a cell and it came back with the following. Does this help?

    Code:
        ActiveChart.SetElement
    ...

    Ken Puls Today, 04:06 AM Go to last post
    Ken Puls

    How to Rename a File from English to Other Language?

    Colo, that was way too easy... I was expecting some massive HTML conversion, or a huge engine to compare each character against a library of Chr codes!...

    Ken Puls Today, 04:02 AM Go to last post
    Ken Puls

    Shared file\macro & IP address

    Oh, and as for the max number of users who can access the file in the shared folder at once...

    • For reading, I believe it's unlimited. (The second and
    ...

    Ken Puls Today, 03:59 AM Go to last post
    Ken Puls

    Shared file\macro & IP address

    ibrahimaa,

    There is no one-line way to get your IP address the way you are getting the username. So you're going to need more code than...

    Ken Puls Today, 03:56 AM Go to last post