Mass conversion of equations to excel formulas

unclefrank58

New Member
Joined
Jul 10, 2019
Messages
4
I deal with equations that are drafted in microsoft word that look like this:

(1.0 x 0.03125 x 0.20 x 187.4237/1920.00)

If I independently put an = sign in front of (1.0 it will turn it into a formula after asking to correct for typo for x to become *

The problem is I have hundreds of these equations and I was wondering if there is a way to turn all the equations into formulas with the answer without doing it individually.

Any ideas?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Welcome to the Board!

Select all the cells you want to apply this to and run this VBA code:
Code:
Sub ConvertFormulas()

    Dim frm As String
    Dim cell As Range
    
    Application.ScreenUpdating = False
    
'   Loop through all cells in selection
    For Each cell In Selection
        frm = "=" & Trim(Replace(cell, " x ", " * "))
        cell.Formula = frm
    Next cell
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
I tried it with a UDF:

Code:
Function EvalString(strTxtString As String)
Application.Volatile
strTxtString = Replace(strTxtString, "x", "*")
EvalString = Evaluate(strTxtString)
End Function
 
Last edited:
Upvote 0
I don't know if a UDF will do what they want here. Based on the following, it sounds like they want to turn it into an active formula:
I was wondering if there is a way to turn all the equations into formulas with the answer without doing it individually.
Using a UDF with the Evaluate function will return the result, not convert the entry into a valid formula, which is why I approached it the way I did.
 
Upvote 0
AH, right...if that's what they wanted versus the result only.
 
Upvote 0
If I understand what the OP wants correctly, and assuming the equations are in Column A, here is another macro that should work...
Code:
Sub MakeEquationIntoFormula()
  Columns("A").Replace "x", "*", xlPart, , False, , False, False
  Columns("A").Replace "(", "=(", xlPart
End Sub
 
Last edited:
Upvote 0
Rick, I was thinking somewhat along those lines but if there are double ((calculations)/whatever) won't that replacement will be a problem.
And, if the formula isn't surrounded by one open and one closed paren, there's a problem also, yes?
 
Last edited:
Upvote 0
Rick, I was thinking somewhat along those lines but if there are double ((calculations)/whatever) won't that replacement will be a problem.
And, if the formula isn't surrounded by one open and one closed paren, there's a problem also, yes?
Yes, but since the OP only gave a single example, and since I know absolutely nothing about his actual data, I have assumed his example is representative of all of his data. If that is not correct, he should show us a sampling of the type of data he actually has to process.
 
Upvote 0
You are welcome.
Glad we were able to help!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top