Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Reading numbers as text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike H - 26 Mar 2008 16:40 GMT
I'm using TextToColumns in a macro to convert several huge text files
to a spreadsheet.  Some of the raw data is numbers but I need everything
to be copied as text.  I found this question numerous times in this
forum but none with the answer I'm looking for.  
The problem is, even with the code below the numbers are wrong.  
For example, there is a difference between "2" and "02" in my data,
but even with the NumberFormat command the text both variations
will copy as "2", and some numeric strings are converted to SciNote.
Is there a way to copy all text from the raw document as text
without any translation at all?

' Force number format to text:
   Cells.Select
   Selection.NumberFormat = "@"
' Convert unformatted text to 15 columns:
   Selection.TextToColumns Destination:=Range("A1"),
DataType:=xlFixedWidth, _
       FieldInfo:=Array(Array(0, 1), Array(5, 1), Array(11, 1), Array(17,
1),  . . . . .

I'm using Excel 2003, with XP Pro.

Mike Henry
Gary''s Student - 26 Mar 2008 17:10 GMT
The problem is that all your codes are 1.

Replace:

Array(0, 1), Array(5, 1), Array(11, 1),.........

with:

Array(0, 2), Array(5, 2), Array(11, 2),..........

Signature

Gary''s Student - gsnu200775

> I'm using TextToColumns in a macro to convert several huge text files
> to a spreadsheet.  Some of the raw data is numbers but I need everything
[quoted text clipped - 19 lines]
>
> Mike Henry
Mike H - 27 Mar 2008 16:03 GMT
Ok, thanks.
That works but the description in the help file sounds like
"0" is for general
"1" is for text
"2" is for a date format.
I guess not.

M.H.
-------------------------------
> "Gary''s Student" wrote:
> The problem is that all your codes are 1.
> Replace:
> Array(0, 1), Array(5, 1), Array(11, 1),.........
> with:
> Array(0, 2), Array(5, 2), Array(11, 2),..........
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.