#1   Report Post  
LeePotts
 
Posts: n/a
Default Leading zeros

I am importing data into Excel from an online database. The values I am
importing are 9 digit numbers and many contain a zero as the leftmost digit.
Whenerver I copy the data into excel it drops any leading zeros even though
I've formatted that column as text. How can I get Excel to retain the
original number format?
  #2   Report Post  
Gary's Student
 
Posts: n/a
Default

It is possible that your import is over-riding the text formatting.

After importing, select the cells (or rows or columns) then:
Format Cells Custom 000000000

This format will always display all nine digits and retain all leading zeros.
--
Gary's Student


"LeePotts" wrote:

I am importing data into Excel from an online database. The values I am
importing are 9 digit numbers and many contain a zero as the leftmost digit.
Whenerver I copy the data into excel it drops any leading zeros even though
I've formatted that column as text. How can I get Excel to retain the
original number format?

  #3   Report Post  
Stefi
 
Posts: n/a
Default

By my experiences nohow. Therefore I wrote a macro that re-transform such
numbers to their original format:

Sub coltransform(transcol, rngstart, rngend, helpcol, formcode)
coldistance = Range(helpcol & 1).Column - Range(transcol & 1).Column
Range(transcol & rngstart & ":" & transcol & rngend).NumberFormat = "@"
Range(helpcol & rngstart).FormulaR1C1 = "=TEXT(RC[-" & coldistance &
"]," & " """ & formcode & """) "
Range(helpcol & rngstart & ":" & helpcol & rngend).Select
Selection.FillDown
Selection.Copy
Range(transcol & rngstart & ":" & transcol & rngend).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Range(helpcol & rngstart & ":" & helpcol & rngend).ClearContents
End Sub

In your case the calling is this:
Call coltransform("A", 1, 100, "B", "000000000")
where the first four arguments are examples, the fourth is the real format
code for 9 digit numbers or rather 9 character long strings containing only
digits.
There is another benefit of using this sub: imported texts don't behave
normally in operations like Autofilter, Sorting, etc. This sub resolves this
problem too.

I hope it will be useful!
Regards,
Stefi

€˛LeePotts€¯ ezt Ć*rta:

I am importing data into Excel from an online database. The values I am
importing are 9 digit numbers and many contain a zero as the leftmost digit.
Whenerver I copy the data into excel it drops any leading zeros even though
I've formatted that column as text. How can I get Excel to retain the
original number format?

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
Format a cell to keep leading zeros. Shadyhosta New Users to Excel 5 July 27th 05 04:37 PM
How do I force leading zeros in an Excel cell? EricKei Excel Discussion (Misc queries) 2 June 15th 05 08:28 PM
Leading zeros Paul Excel Discussion (Misc queries) 4 June 12th 05 04:04 AM
save text field w/ leading zeros in .csv format & not lose zeros? Ques Excel Discussion (Misc queries) 1 May 4th 05 06:21 PM
Displaying leading zeros in an Excel spreadsheet marianthelibrarian Excel Discussion (Misc queries) 1 January 25th 05 02:08 PM


All times are GMT +1. The time now is 07:37 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"