Reputation: 25
Hi how can I get around vba is converting a cell automatic to a data format when I add a value like 10 - 12 I just want the value in the cell to be 10 - 12 not a date
the code I use is "cFli is the value 10 - 12":
tsheet.Range("E2").Value = cFli
Upvotes: 0
Views: 27
Reputation: 23974
You can prepend a single-quotation mark to the value of a cell, which indicates to Excel to treat the rest of the string as text:
tsheet.Range("E2").Value = "'" & cFli
Note: The '
does not become part of the cell contents, although it will appear when editing the cell in future.
Alternatively, you can achieve the same thing by formatting the cell using the Text
format:
tsheet.Range("E2").NumberFormat = "@"
tsheet.Range("E2").Value = cFli
Note: The formatting must be done before putting the value into the cell.
Upvotes: 1