David Kovacs
David Kovacs

Reputation: 45

Excel formula from textfile into cell

I want to get formula from textfile into cell to identify the rows by named range. I have this macro:

Dim objStream
Dim strData As String
Set objStream = CreateObject("ADODB.Stream")
objStream.Charset = "utf-8"
objStream.Open
objStream.LoadFromFile ("path_of_txt_file")
strData = objStream.ReadText()
strData = Trim(Application.Clean(strData))
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1").Select
ActiveCell.Value = "Name"
Range("A2").Select

Range("A2").FormulaR1C1 = strData

The textfile contains like this:

=IF(
    OR(
        named range="this";
        named range="that";
        named range="something"
    );
    "True";
    "False"
)
...

Its a nested IF formula.

Without the equality sign it work, but i need to put it mannually. With that, i get this error

Runtime error '1004':
Application-defined or object-defined error

How can i fix this? I tried with Value instead of FormulaR1C1, but the same results.

Thanks for all answers!

Upvotes: 0

Views: 57

Answers (1)

Gowtham Shiva
Gowtham Shiva

Reputation: 3875

There doesnt seem to be a problem with Range("A2").FormulaR1C1 = strData. Replacing the ; in the formula with , worked.

Posting the answer as it worked for OP.

Upvotes: 2

Related Questions