importing formulas

joebars

New Member
Joined
Aug 27, 2002
Messages
3
I would like to know if there is any way to force excel to recognize an imported cell as a formula. When I import a text file containing a cell beginning with = excel adds a ' in front of the = to convert it to a text cell.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi joebars,

Here is a macro that will convert all text strings on the active worksheet that start with "=" to formulas:

Sub TextToFormulas()
'changes any cells on the active worksheet that contain text
'that starts with "=" to a formula. This enables formulas to
'be imported from a file as text.
Dim Cell As Range
For Each Cell In ActiveSheet.UsedRange
If Not Cell.HasFormula And Left(Cell.Value, 1) = "=" Then
Cell.Formula = Cell.Value
End If
Next Cell
End Sub

This macro should be placed in a standard macro module (Alt-TMV, Alt-IM, paste code into VBE code pane).
 
Upvote 0
Thanks Damon. I'm still hoping to find a lead character (similar to the ' that excel places in the cell) that I can place in the text file so that the formula will work when the sheet is opened (I'm actually exporting the text file from another app that saves it to an excel format). In the meantime, the macro will help.
 
Upvote 0
Hi again joebars,

It is possible to read the file setting the formulas at the same time if you do it using VBA I/O rather than importing it as a text file. By VBA I/O I mean writing an import macro that reads the data and writes it into the cells as values if no leading equal sign and as formulas otherwise. If you want to investigate this you can read up on it in the VBA helps. See the keywords Open, EOF, Close, and Input #.

Damon
 
Upvote 0

Forum statistics

Threads
1,206,808
Messages
6,074,982
Members
446,109
Latest member
ab3g1nner

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