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 / January 2008

Tip: Looking for answers? Try searching our database.

Format a number field as text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tony Girgenti - 26 Jan 2008 19:08 GMT
Hello.

I've developed a VB 6.0 program to import a fixed length fileds, ascii, text
file into a new Excel workbook.

I programmatically design a recordset and import the text file into the
recordset using these kinds of statements:

   With casInputFileRecordset
     .Fields.Append "ItemNumber", adChar, 16, adFldUpdatable

   Do While Not casInputStream.AtEndOfStream
       casInputFileLineString = casInputStream.ReadLine()
       With casInputFileRecordset
           .AddNew
           !ItemNumber = Trim(Mid(casInputFileLineString, 73, 16))

There are other fields, just not listed for brevity sake.

Then in the business logic, i populate the worksheet with:

       newExcelWorkSheet.Range("A2").CopyFromRecordset casInputRecordset

All this works and i'm very happy that i was able to complete such a task.

Sometimes the text file ItemNumber is just blank(12 spaces) and it's not
really a number, it can be alpha.

When i open the workbook, the field that contains ItemNumber has a little
tag next to it that says:
"The number in this field is formatted as text or preceded by an
apostrophe."

Very annoying.  The ItemNumber column is programmatically formatted this
way.

       newExcelWorkSheet.Columns("C").NumberFormat = "Text"

I also tried "Text" without the quotes.  That displays the field with all
pound signs (#).

Also, the ItemNumber fields in Excel have twelve spaces in them including
the data.  If the text file is blank for that field, it imports 12 spaces.

Does anybody know how to format that field so that it simply shows up as
text? and if it is blank, to make it an empty field not 12 spaces?

Any help would be gratefully appreciated.

Thanks,
Tony
Jim Cone - 27 Jan 2008 14:17 GMT
Tony,
Try changing "Text" to "@"...
  newExcelWorkSheet.Columns("C").NumberFormat = "@"
Signature

Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

Tony Girgenti - 28 Jan 2008 20:02 GMT
Hello Jim.

I'm not sure of what "@" is supposed to do, but that did not work.

Thanks,
Tony

> Tony,
> Try changing "Text" to "@"...
>   newExcelWorkSheet.Columns("C").NumberFormat = "@"
Jim Cone - 28 Jan 2008 21:00 GMT
"@" is the designator that tells Excel to format cells as text.
"General" is the default format.
Signature

Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)

"Tony Girgenti"
<tony(nospam)@lakesideos.com>
wrote in message
Hello Jim.
I'm not sure of what "@" is supposed to do, but that did not work.
Thanks,
Tony

"Jim Cone"
wrote in message

>
> Tony,
> Try changing "Text" to "@"...
>   newExcelWorkSheet.Columns("C").NumberFormat = "@"
 
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.