DDBE
DDBE

Reputation: 345

VBA - write "=>" as string in a cell

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

Upvotes: 2

Views: 2651

Answers (2)

Scott Craner
Scott Craner

Reputation: 152585

You can format it as text before entering the value:

With ActiveSheet.Range("A1")
    .NumberFormat = "@"
    .Value = "=>"
End With

Upvotes: 7

Pᴇʜ
Pᴇʜ

Reputation: 57743

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.

Upvotes: 4

Related Questions