Entering '=' as the first character in a cell

前端 未结 2 1907
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-13 11:09

I have a VBA macro that runs and often needs to have \"=\" as the first character in a cell. Cells are filled with such values as \"= Domestic\", \"<> Domestic\", etc.

相关标签:
2条回答
  • 2021-01-13 11:55

    Add a single quote ' at the start of the string:

    Cells(row, col).Value = "'" & x
    

    and you will get what you want.

    0 讨论(0)
  • 2021-01-13 12:10

    This is an alternate method

    Sub Test()
        Dim myRange As Range
    
        Set myRange = Range("C:C") 'Column "C"
        myRange.NumberFormat = "@" 'Set cell format of range to plain text
        myRange.Cells(1, 1) = "= Domestic"
    
    End Sub
    

    Compared to manji's answer, it provides no performance or size enhancement...just different.

    0 讨论(0)
提交回复
热议问题