Software Guide

How to convert text to formula in Excel

We know an Excel function “FORMULATEXT” which converts Formula into Text. What if you want to do the reverse i.e. convert excel text into active formula?

Problem statement

Let’s say your Excel cell has following string or text.

A1+B1

Now you want to convert the above text into active formula that evaluates it instead of just printing text.

Solution

Excel doesn’t have a built-in function that directly convert text strings to active formulas, However, using a simple VBA script, you can create a custom function that does the same.

The following VBA script converts the text or string into an active formula that gets actually evaluated.

Function Eval(ByVal formulaText As String) As Variant
    On Error Resume Next
    Eval = Evaluate(formulaText)
End Function

To use the above VB code in Excel Workbook, follow these steps

  1. Right click the sheet name and click “View Code
  2. Go to Insert > Module
  3. Copy the above VB code and paste it as shown below.
  4. Press “Ctrl + S” to save it as Macro Enabled Workbook so that you can use this formula.

Presently this formula is only available in present sheet. To make it available in all Excel sheets follow steps provided here.

Use Eval function defined above to evaluate or convert text into active formula.

  • Go to cell where you want to get evaluate text as formula.
  • type “=Eval(<cell containing text formula>)” and hit enter. Inside Eval function, refer cell containing text formula which you need to convert into active formula in Excel.

wisdomiseme.com

Recent Posts

The Sieve of Eratosthenes for Prime Numbers with Python and Java Code

The Sieve of Eratosthenes is a popular algorithm used to find all prime numbers up…

2 weeks ago

Unlocking the Mystery of Irrational Numbers: A Fun Guide for Young Mathematicians

Introduction Have you ever wondered about numbers that don't quite fit in with the rest?…

4 months ago

Trick by which you will never forget capital of Sudan

Struggling to remember the capitals of countries? Well, you’re not alone. Today, we’re going to…

6 months ago

(¿) Upside down question mark shortcut for Ms Word [2024]

Works with Microsoft® Word® 2010, 2013, 2016, 2019, 2021, 365 and above Upside down question mark (¿)…

7 months ago

Nabla Symbol (∇) in MS Word and its shortcut

Microsoft Word has different ways to add symbol. Nabla symbol (∇) is one of the…

8 months ago

Remapping Keys in Windows using PowerToys

Broken keys in your keyboard or just want to remap keys in Windows no need…

8 months ago