Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatically default a column to "text" rather than numbers?

Status
Not open for further replies.

kubu

Programmer
Jan 10, 2001
23
US
I'm a VB programmer, but I haven't done much with VBA and Office. Here's my problem:

I have a report that users export to a .csv file. The first column of this report contains number strings. These numbers are identifiers that may begin with a leading zero (e.g., 05678). Excel converts these strings to integers, and truncates the leading zero.

Any ideas on how I can configure or program Excel to automatically set the format of a column to "text" for this report? The report name and layout are static.

Thanks!
Mark
 
File > Open (all file types)

Select text file. 3rd screen of Text Import wizard there is a frame "Column Data Format"

I selected "Text" from there with a similar dummy data file and the leading zeroes were retained. SuperBry!
 
Or alternatively, import as numbers, then change the format of the 1st column to custom - 000000 (or however many digits there are) - this will retain number properties AND leading zeros
HTH
~Geoff~
 
Consider either of these:

a = CStr(yourvariable)
'or
b = Format(yourvariable, "@")

 
Thanks, all, for your input! I was already aware of the methods mentioned, but I'm looking for a way to automate the process -- i.e., no user interaction.

In other words...

1. the user double-clicks on the .csv file or loads the file from within Excel...

2. Excel somehow detects that this file is one that needs special formatting, based on the file name...

3. Excel displays the file with the column in question correctly formatted.

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top