Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Set datatype of a cell?

I'm creating an Excel spreadsheet from a DataTable. I've got the code all
working, but the data that I'm writing out for one particular column is
"001". Excel is truncating that value to be a number, so it only displays "1".

How can I set the datatype of the cell to Text, so it will preserve the
leading zeroes?

Thanks
Chris
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Set datatype of a cell?

ActiveCell.NumberFormat = "0000"
--
jb


"CCusson15" wrote:

I'm creating an Excel spreadsheet from a DataTable. I've got the code all
working, but the data that I'm writing out for one particular column is
"001". Excel is truncating that value to be a number, so it only displays "1".

How can I set the datatype of the cell to Text, so it will preserve the
leading zeroes?

Thanks
Chris

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Set datatype of a cell?

Thanks John!

One followup, I know the datatype of the column that I'm reading from in the
DataTable (say DateTime, int, string, etc.)

Is there any way I can translate those types to Excel, other that setting
the NumberFormat to those zeros, etc.?

Thanks,
Chris

"john" wrote:

ActiveCell.NumberFormat = "0000"
--
jb


"CCusson15" wrote:

I'm creating an Excel spreadsheet from a DataTable. I've got the code all
working, but the data that I'm writing out for one particular column is
"001". Excel is truncating that value to be a number, so it only displays "1".

How can I set the datatype of the cell to Text, so it will preserve the
leading zeroes?

Thanks
Chris

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Set datatype of a cell?

do you mean something like:

NumberFormat = "dd/mm/yyyy h:mm" ?

suggest you have a read VBA helpfile under NumberFormat for further guidance.
--
jb


"CCusson15" wrote:

Thanks John!

One followup, I know the datatype of the column that I'm reading from in the
DataTable (say DateTime, int, string, etc.)

Is there any way I can translate those types to Excel, other that setting
the NumberFormat to those zeros, etc.?

Thanks,
Chris

"john" wrote:

ActiveCell.NumberFormat = "0000"
--
jb


"CCusson15" wrote:

I'm creating an Excel spreadsheet from a DataTable. I've got the code all
working, but the data that I'm writing out for one particular column is
"001". Excel is truncating that value to be a number, so it only displays "1".

How can I set the datatype of the cell to Text, so it will preserve the
leading zeroes?

Thanks
Chris

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Set datatype of a cell?

John,

I don't necessarily know if there are leading zeros, and if there are any,
whether to keep them or not. Is it possible within numberformat to set the
type as Text, like in Excel itself?

"john" wrote:

do you mean something like:

NumberFormat = "dd/mm/yyyy h:mm" ?

suggest you have a read VBA helpfile under NumberFormat for further guidance.
--
jb


"CCusson15" wrote:

Thanks John!

One followup, I know the datatype of the column that I'm reading from in the
DataTable (say DateTime, int, string, etc.)

Is there any way I can translate those types to Excel, other that setting
the NumberFormat to those zeros, etc.?

Thanks,
Chris

"john" wrote:

ActiveCell.NumberFormat = "0000"
--
jb


"CCusson15" wrote:

I'm creating an Excel spreadsheet from a DataTable. I've got the code all
working, but the data that I'm writing out for one particular column is
"001". Excel is truncating that value to be a number, so it only displays "1".

How can I set the datatype of the cell to Text, so it will preserve the
leading zeroes?

Thanks
Chris



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Set datatype of a cell?


Something like this:

Columns("D:D").NumberFormat = "@"

and then copy the data will preserve any leading zeroes.
Reply
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
DateTime datatype in VBA Alex Excel Programming 4 January 30th 07 06:36 PM
determining datatype davegb Excel Programming 8 December 1st 05 09:29 PM
DataType Property Access101 Excel Programming 3 August 25th 05 08:15 PM
need help- SUB: DATATYPE FOR A CELL.. monika Excel Programming 1 February 13th 04 02:13 PM
How do I change the datatype of a cell? Casper Hornstrup Excel Programming 5 December 10th 03 01:46 PM


All times are GMT +1. The time now is 04:50 PM.

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

About Us

"It's about Microsoft Excel"