Quick question:
I want to insert a row like 10/3 into a cell like this:
10/3
Worksheets("Sheet1").Range("A1").Value = "10/3"
But Excel automatically formats the cell as a date or number. I want it to be like a string.
How can I achieve this using VBA?
Worksheets("Sheet1").Range("A1").NumberFormat = "@" Worksheets("Sheet1").Range("A1").Value = "10/3"
add one quotation mark ' to the value - in your example it will make a string
'
Worksheets("Sheet1").Range("A1").Value = "'10/3"
or, if you have a variable containing data
Worksheets("Sheet1").Range("A1").Value = "'" & MyValue
The solution .NumberFormat = "@" also worked for me. Thank you very much, unfortunately, beginners may not give msarks, but I would give 10 out of ten. My snippet:
Cells(Row, Column).NumberFormat = "@" Cells(Row, Column).Value = Trim(CellValue)
Source: https://habr.com/ru/post/1490746/More articles:Adding different types of items as a list - androidMultiplying text views as a list - androidFailed to send file to openfire group chat - file-transferLibgdx line speed not working - javaHow to use atan2 () in combination with other Radian angle systems - mathDuplicate Meteor code - javascriptText On each panel of the folded histogram d3.js - labelComplete the list of checkboxes that some probably are not checked in PHP - arraysWeird C ++ Behavior when printing our time on cout - c ++Dynamic expansion of the data table. - rAll Articles