2

I'm trying to write in a cell this string "=>". Macro gives "error 1004".

Macro works correctly if I write "=>x" where x stands for another character.

What am I doing wrong?

Thanks

Mesut Akcan
  • 899
  • 7
  • 19
DDBE
  • 325
  • 3
  • 13
  • 3
    Type a single quote in front of it otherwise it is interpreted as the start of a formula. Please provide the line of VBA code that produces the error. – trincot Nov 19 '18 at 14:30

2 Answers2

7

You can format it as text before entering the value:

With ActiveSheet.Range("A1")
    .NumberFormat = "@"
    .Value = "=>"
End With
Scott Craner
  • 148,073
  • 10
  • 49
  • 81
  • Helped me to solve an old question +1 :-) see [Avoid error 1004 writing UF ListBox array (back) to sheet](https://stackoverflow.com/questions/46256010/excel-vba-avoid-error-1004-writing-uf-listbox-array-to-sheet) – T.M. Nov 19 '18 at 21:08
  • Helped me. Thanks so much. I was parsing a text file and writing to a table. Some of the text contained equals signs and caused a run-time error. By formatting the range to text this solved the problem. – Matt L Jan 23 '20 at 06:32
4

The issue here is that Excel understands => as the beginning of a formula because it starts with an equal sign, and you get the error because the formula is incomplete.

If you want to force Excel to understand it as text add a single quote as first character:

Range("A1").Value = "'=>"

Excel will not show the quote ' but it will recognize the cell content as text instead of a formula.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73