I want to insert a string of type 10/3
in a cell like this:
Worksheets("Sheet1").Range("A1").Value = "10/3"
But Excel automatically formats the cell as a date or a number. I want to have it as a string.
How can I achieve this with VBA?
Worksheets("Sheet1").Range("A1").NumberFormat = "@"
Worksheets("Sheet1").Range("A1").Value = "10/3"
add a single quote '
before the value - in your example, it would make the line
Worksheets("Sheet1").Range("A1").Value = "'10/3"
or, if you have a variable that holds the data
Worksheets("Sheet1").Range("A1").Value = "'" & MyValue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With