简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM