Need to set Column format as text
Hi Deluth,
For example, a value of "2200505000099" became "2.20051E+12"
This appears only to happen with 12+ digit numbers.
For single cell ranges, the following worked for me:
Sub Test1()
Dim destCell As Range, srcCell As Range
Set destCell = Range("A1")
Set srcCell = Range("C1")
srcCell.Value = "2200505000099" '13 digit Test value
With destCell
.NumberFormat = "@"
.Value = CStr(srcCell.Value)
End With
End Sub
For multi-cell ranges, the following worked for me:
Sub Test2()
Dim destRng As Range
Dim srcRng As Range
Dim rcell As Range
Set srcRng = Range("C1:C10")
Set destRng = Range("A1:A10")
destRng.NumberFormat = "@"
destRng.Value = srcRng.Value
For Each rcell In destRng
rcell.Value = CStr(rcell.Value)
Next
End Sub
---
Regards,
Norman
"deluth" wrote in message
...
Hi Norman,
Thank you for the quick response. Unfortunately, this method did not work
for me. I set the format as you suggested: ...NumberFormat = "@" in the
beginning of the subroutine. In the middle, I set the cell value as so:
destCell.Value = srcCell.Value
Some of srcCell.Value are text, but most are numbers, but I wanted the
entire column to be represented as text. The resulting value for the
cells
with numbers were in numbers. For example, a value of "2200505000099"
became
"2.20051E+12"
Should I have done a string conversion? If so, how do I know when the
cell
value starts with a text and when it starts with a number? Do I need to
test
the cell value for numeric and then convert? There must be an easy way to
do
this...
Any help would greatly be appreciated!
|