Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
hkslater
 
Posts: n/a
Default Insert Leading Zeros

I have a data field that I want to instert a leading zero (where necessary)
so that I may sort the data correctly. Is there an easy way to do this?

My service codes currently sort as follows:

32-1
32-10
32-11
32-12
32-2
32-20
32-21
32-3

Is there formula that will insert a leading zero into the 32-1, 32-2, 32-3
etc. to make it 32-01, 32-02, 32-03?

Thanks for the help.
  #2   Report Post  
Frank Kabel
 
Posts: n/a
Default

Hi
you may try the following in a helper column:
=LEFT(A1,FIND("-",A1) & TEXT(--(MID(A1,FIND("-",A1),10)),"00")

--
Regards
Frank Kabel
Frankfurt, Germany

"hkslater" schrieb im Newsbeitrag
...
I have a data field that I want to instert a leading zero (where

necessary)
so that I may sort the data correctly. Is there an easy way to do

this?

My service codes currently sort as follows:

32-1
32-10
32-11
32-12
32-2
32-20
32-21
32-3

Is there formula that will insert a leading zero into the 32-1, 32-2,

32-3
etc. to make it 32-01, 32-02, 32-03?

Thanks for the help.


  #3   Report Post  
Frank Kabel
 
Posts: n/a
Default

Hi
or another alternative (a little bit shorter):
=TEXT(--SUBSTITUTE(A1,"-",""),"00-00")

--
Regards
Frank Kabel
Frankfurt, Germany

"hkslater" schrieb im Newsbeitrag
...
I have a data field that I want to instert a leading zero (where

necessary)
so that I may sort the data correctly. Is there an easy way to do

this?

My service codes currently sort as follows:

32-1
32-10
32-11
32-12
32-2
32-20
32-21
32-3

Is there formula that will insert a leading zero into the 32-1, 32-2,

32-3
etc. to make it 32-01, 32-02, 32-03?

Thanks for the help.


  #4   Report Post  
hkslater
 
Posts: n/a
Default

This actually got me 03-01 instead of 31-01.

"Frank Kabel" wrote:

Hi
or another alternative (a little bit shorter):
=TEXT(--SUBSTITUTE(A1,"-",""),"00-00")

--
Regards
Frank Kabel
Frankfurt, Germany

"hkslater" schrieb im Newsbeitrag
...
I have a data field that I want to instert a leading zero (where

necessary)
so that I may sort the data correctly. Is there an easy way to do

this?

My service codes currently sort as follows:

32-1
32-10
32-11
32-12
32-2
32-20
32-21
32-3

Is there formula that will insert a leading zero into the 32-1, 32-2,

32-3
etc. to make it 32-01, 32-02, 32-03?

Thanks for the help.



  #5   Report Post  
Myrna Larson
 
Posts: n/a
Default

Hi, Frank:

You are staying up too late <bg!

Your first formula was missing a left paren before the first &. After that
fix, it gave me two dashes in the results, which was fixed by inserting +1
before the ",10" in the MID formula. So it ended up as this, which worked
correctly.

=LEFT(A1,FIND("-",A1)) & TEXT(--(MID(A1,FIND("-",A1)+1,10)),"00")

For the 2nd, shorter formula, no cigar on that one <bg. It inserts the
additional zero at the front instead of after the dash.

32-1 comes out as 03-21 instead of 32-01

Myrna Larson


On Tue, 16 Nov 2004 22:42:19 +0100, "Frank Kabel"
wrote:

Hi
or another alternative (a little bit shorter):
=TEXT(--SUBSTITUTE(A1,"-",""),"00-00")




  #6   Report Post  
Tim C
 
Posts: n/a
Default

Assuming no more than 2 digits to the right of the dash, try:

=LEFT(A1,FIND("-",A1))&TEXT(RIGHT(A1,2),"00;00")

Tim C

"hkslater" wrote:

I have a data field that I want to instert a leading zero (where necessary)
so that I may sort the data correctly. Is there an easy way to do this?

My service codes currently sort as follows:

32-1
32-10
32-11
32-12
32-2
32-20
32-21
32-3

Is there formula that will insert a leading zero into the 32-1, 32-2, 32-3
etc. to make it 32-01, 32-02, 32-03?

Thanks for the help.



  #7   Report Post  
hkslater
 
Posts: n/a
Default

This worked thank you.

"Tim C" wrote:

Assuming no more than 2 digits to the right of the dash, try:

=LEFT(A1,FIND("-",A1))&TEXT(RIGHT(A1,2),"00;00")

Tim C

"hkslater" wrote:

I have a data field that I want to instert a leading zero (where necessary)
so that I may sort the data correctly. Is there an easy way to do this?

My service codes currently sort as follows:

32-1
32-10
32-11
32-12
32-2
32-20
32-21
32-3

Is there formula that will insert a leading zero into the 32-1, 32-2, 32-3
etc. to make it 32-01, 32-02, 32-03?

Thanks for the help.




  #8   Report Post  
N Harkawat
 
Posts: n/a
Default

Assuming that their are only 2 characters left of "-"
=IF(LEN(MID(A1,3,1024))=2,SUBSTITUTE(A1,"-","-0"),A1)


"hkslater" wrote in message
...
I have a data field that I want to instert a leading zero (where

necessary)
so that I may sort the data correctly. Is there an easy way to do this?

My service codes currently sort as follows:

32-1
32-10
32-11
32-12
32-2
32-20
32-21
32-3

Is there formula that will insert a leading zero into the 32-1, 32-2, 32-3
etc. to make it 32-01, 32-02, 32-03?

Thanks for the help.



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
insert a JPEG into EXCEL 2002 mckee Excel Discussion (Misc queries) 3 March 11th 05 05:03 PM
Challenging Charting C TO Charts and Charting in Excel 0 January 17th 05 06:57 PM
Adding Leading Zeros to Text Jenn Excel Discussion (Misc queries) 4 January 12th 05 06:51 PM
How do I display leading zeros so I can export a fixed in Excel? World Referee and accountant Excel Discussion (Misc queries) 2 January 3rd 05 04:18 PM


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

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

About Us

"It's about Microsoft Excel"