[Excel VBA] Format a cell as text
Solved
Thiby
-
holden -
holden -
Hello,
First of all, thank you for being interested in my little problem (noob problem, it must be said...)
Let me present the facts. I'm desperately trying to format a cell in an Excel sheet to receive string values.
I've gone through quite a few discussions online without success. Moreover, my friend Google seems to be on vacation...
I’ll explain why I need this. I have numbers like: 0000573763.
Unfortunately, if I just drop these numbers into the cell, my "0"s disappear without even saying goodbye...
However, by setting the cells to text format, I can keep my numbers intact. So I thought about writing something like: Cells(row, column).stringFormat = true;
(After all, you can write: cells(row, column).numberFormat= ...)
But obviously it was too good to work...
So that’s my little problem.
Hoping someone will lend me a brain! Thanks in advance :)
First of all, thank you for being interested in my little problem (noob problem, it must be said...)
Let me present the facts. I'm desperately trying to format a cell in an Excel sheet to receive string values.
I've gone through quite a few discussions online without success. Moreover, my friend Google seems to be on vacation...
I’ll explain why I need this. I have numbers like: 0000573763.
Unfortunately, if I just drop these numbers into the cell, my "0"s disappear without even saying goodbye...
However, by setting the cells to text format, I can keep my numbers intact. So I thought about writing something like: Cells(row, column).stringFormat = true;
(After all, you can write: cells(row, column).numberFormat= ...)
But obviously it was too good to work...
So that’s my little problem.
Hoping someone will lend me a brain! Thanks in advance :)
Configuration: Windows XP Firefox 2.0.0.5
9 réponses
Hello,
To maintain the text property of the cell, use:
Cells(row, column).NumberFormat = "@" ' Text Format
Example:
Lupin
To maintain the text property of the cell, use:
Cells(row, column).NumberFormat = "@" ' Text Format
Example:
Sub CaptureData() Dim Value As Variant, Data As String Cells(Row, column) = "@" 'Text ' If you do not perform the control Data = Cells(Row, column).Value ' If you perform the control Value = Cells(Row, column).Value Data = CStr(Value) End Sub '
Lupin