Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting value into Excel cell instead of formula

I have a VBA script that inserts long strings into Excel cells. In some cases, the string begins with a =. It seems like Excel interprets this as a formula and I get an Out of Memory error due to the memory limitations of formulas.

How do I tell Excel that I am writing a value, not a formula? Currently, I am doing this:

ws.Range("A" & row) = Mid(xml, first, CHUNK_SIZE)

I have tried the following code, but it doesn't work...

ws.Range(...).Value = ....
like image 275
lucks Avatar asked Dec 02 '25 11:12

lucks


2 Answers

Append a ' before the = sign:

Sub Test()

     'This returns 30 in cell Al
      Range("A1").Value = "=SUM(10,10,10)"

      'This shows formula as text in cell A2
      Range("A2").Value = "'" & "=SUM(10,10,10)"

End Sub
like image 61
Alex P Avatar answered Dec 05 '25 02:12

Alex P


Add an apostrophe ' to the beginning of the string (that excel thinks is a formula) and excel should interpret it as a string instead of a formula.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!