ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   zero filled changed to non-zero filled (https://www.excelbanter.com/excel-programming/367451-zero-filled-changed-non-zero-filled.html)

JPM

zero filled changed to non-zero filled
 
Hello,

I'm filling a worksheet with a recordset. I need to know how to set the
format of a cell or column . . .
The data is a zip code; it may have a leading zero. How do I retain the zero
when feeding the worksheet? i.e. it is interpreting the data as a number and
stripping the leading zero. I know I can manually set this in Excel. I need
to programmatically set the cell or column to retain the zero.

'Sht = worksheet, rst = recordset.

Sht.Cells(i, i1 + 1) = rst.fields("zip").value

Any help is much appreciated.

JPM



Mark Dev[_2_]

zero filled changed to non-zero filled
 
JPM,

How about padding the number with leading zero's? Try this:

Sht.Cells(i, i1 + 1) = Right$("00000" & Trim$(rst.Fields("zip").Value), 5)

Regards,
Mark


"JPM" wrote in message
...
Hello,

I'm filling a worksheet with a recordset. I need to know how to set the
format of a cell or column . . .
The data is a zip code; it may have a leading zero. How do I retain the
zero when feeding the worksheet? i.e. it is interpreting the data as a
number and stripping the leading zero. I know I can manually set this in
Excel. I need to programmatically set the cell or column to retain the
zero.

'Sht = worksheet, rst = recordset.

Sht.Cells(i, i1 + 1) = rst.fields("zip").value

Any help is much appreciated.

JPM





All times are GMT +1. The time now is 08:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com