LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Need to set Column format as text

I don't think you'd need this at the end:

For Each rcell In destRng
rcell.Value = CStr(rcell.Value)
Next



Norman Jones wrote:

Hi Deluth,

And if the ranges were multi-area ranges, perhaps something like:

Sub Test3()
Dim destRng As Range
Dim srcRng As Range
Dim rcell As Range
Dim i As Long

Set srcRng = Range("C1:C3,C5:C7,C10:C11")
Set destRng = Range("A1:A3,B5:B7,A10:A11")

destRng.NumberFormat = "@"

For i = 1 To srcRng.Areas.Count
destRng.Areas(i).Value = srcRng.Areas(i).Value
Next i

For Each rcell In destRng
rcell.Value = CStr(rcell.Value)
Next
End Sub

---
Regards,
Norman

"Norman Jones" wrote in message
...
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


--

Dave Peterson
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text format - setting text colour with code NDBC Excel Discussion (Misc queries) 6 July 1st 09 10:15 PM
Max value in 1 column when all values format are text coco Excel Programming 2 June 21st 05 07:40 PM
Setting a column to Text datatype [email protected] Excel Programming 1 January 20th 05 04:58 PM
Column format as Text Bruce Roberson[_5_] Excel Programming 3 February 14th 04 02:08 AM
column format as text Sumesh[_2_] Excel Programming 2 February 9th 04 01:38 PM


All times are GMT +1. The time now is 05:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"