Home>Blogs>VBA>UDF for Evaluate a Formula in Excel
Evaluate Formula
VBA

UDF for Evaluate a Formula in Excel

In this article you will learn how to create a User Defined Function to evaluate a formula in Excel. You will also learn how to get text of formula using a User Defined Function and FORMULATEXT (Excel 2013 and above).

Evaluate Formula

Below is the code to create the User Defined Function to evaluate a formula in Excel

Function Evaluate_Formula(formula_text As String) As Variant

     Application.Volatile
    Evaluate_Formula = Application.Evaluate(VBA.Trim(formula_text))

End Function

 

Text of Formula:

If you are using Excel 2013 and above version, then you can use “=FORMULATEXT” in Excel. For Excel 2010 and below version I have created a User Defined Function.

Below is the code-

Function Text_Of_Formula(rng As Range) As String


      Application.Volatile
      Text_Of_Formula = rng.Formula


End Function

 

You can copy this code in Personal Macro so that it will be available for each workbook.

Click here to download the practice workbook.

 

Watch the step by step video:

PK
Meet PK, the founder of PK-AnExcelExpert.com! With over 15 years of experience in Data Visualization, Excel Automation, and dashboard creation. PK is a Microsoft Certified Professional who has a passion for all things in Excel. PK loves to explore new and innovative ways to use Excel and is always eager to share his knowledge with others. With an eye for detail and a commitment to excellence, PK has become a go-to expert in the world of Excel. Whether you're looking to create stunning visualizations or streamline your workflow with automation, PK has the skills and expertise to help you succeed. Join the many satisfied clients who have benefited from PK's services and see how he can take your Excel skills to the next level!
https://www.pk-anexcelexpert.com