Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5
Default adding leading zero in Excel

How do I add zeros to numbers in a cell? ex: R1,R12,R152 to R001,R012,R152
This needs to be done in many cells. Thanks
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default adding leading zero in Excel

=LEFT(A1,1) & TEXT(RIGHT(A1,LEN(A1)-1),"000")

--
Gary''s Student - gsnu200744
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5
Default adding leading zero in Excel

I could not get this to work.

"Gary''s Student" wrote:

=LEFT(A1,1) & TEXT(RIGHT(A1,LEN(A1)-1),"000")

--
Gary''s Student - gsnu200744

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default adding leading zero in Excel

That's O.K. We can solve this.

In A1 thru A3 I entered:

R1
R12
R152


I put my formula in B1 thru B3 and see:

R1 R001
R12 R012
R152 R152

What do you see?


--
Gary''s Student - gsnu200744


"ENFGDC4S" wrote:

I could not get this to work.

"Gary''s Student" wrote:

=LEFT(A1,1) & TEXT(RIGHT(A1,LEN(A1)-1),"000")

--
Gary''s Student - gsnu200744

  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5
Default adding leading zero in Excel

This is where my problem is. Here is an example of one of the cells:
C5,C16,C30,C38,C54,C91,C98,C136,C147
I can have a few hundred of these alpha numeric characters in one cell.
Thanks for your time.

"Gary''s Student" wrote:

That's O.K. We can solve this.

In A1 thru A3 I entered:

R1
R12
R152


I put my formula in B1 thru B3 and see:

R1 R001
R12 R012
R152 R152

What do you see?


--
Gary''s Student - gsnu200744


"ENFGDC4S" wrote:

I could not get this to work.

"Gary''s Student" wrote:

=LEFT(A1,1) & TEXT(RIGHT(A1,LEN(A1)-1),"000")

--
Gary''s Student - gsnu200744



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default adding leading zero in Excel

O.K.

You see my mis-understanding.

I can solve this with visual basic.

Check back later
--
Gary''s Student - gsnu200744


"ENFGDC4S" wrote:

This is where my problem is. Here is an example of one of the cells:
C5,C16,C30,C38,C54,C91,C98,C136,C147
I can have a few hundred of these alpha numeric characters in one cell.
Thanks for your time.

"Gary''s Student" wrote:

That's O.K. We can solve this.

In A1 thru A3 I entered:

R1
R12
R152


I put my formula in B1 thru B3 and see:

R1 R001
R12 R012
R152 R152

What do you see?


--
Gary''s Student - gsnu200744


"ENFGDC4S" wrote:

I could not get this to work.

"Gary''s Student" wrote:

=LEFT(A1,1) & TEXT(RIGHT(A1,LEN(A1)-1),"000")

--
Gary''s Student - gsnu200744

  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,202
Default adding leading zero in Excel

I guess we should further clarify... is the part in front of the number
always a SINGLE letter character? Is the number part always going to be
three digits long? Any other info we should know?

Rick


"ENFGDC4S" wrote in message
...
This is where my problem is. Here is an example of one of the cells:
C5,C16,C30,C38,C54,C91,C98,C136,C147
I can have a few hundred of these alpha numeric characters in one cell.
Thanks for your time.

"Gary''s Student" wrote:

That's O.K. We can solve this.

In A1 thru A3 I entered:

R1
R12
R152


I put my formula in B1 thru B3 and see:

R1 R001
R12 R012
R152 R152

What do you see?


--
Gary''s Student - gsnu200744


"ENFGDC4S" wrote:

I could not get this to work.

"Gary''s Student" wrote:

=LEFT(A1,1) & TEXT(RIGHT(A1,LEN(A1)-1),"000")

--
Gary''s Student - gsnu200744


  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,202
Default adding leading zero in Excel

I can solve this with visual basic.

I'll save you the trouble.<g

If there is only one leading letter character for each "field" in the cell
and if the number part always needs to be three digits long, then this sub
should work...

Sub AddZeroes()
Dim C As Range
Dim Fields() As String
For Each C In Selection
Fields = Split(C.Value, ",")
For X = 0 To UBound(Fields)
Fields(X) = Left$(Fields(X), 1) & _
Format$(Mid$(Fields(X), 2), "000")
Next
C.Value = Join(Fields, ",")
Next
End Sub

To ENFGDC4S:
=============
All you have to do is right-click the sheet tab at the bottom, and "View
Code"; then copy/paste the above routine into the sheet's code window. Once
you have done that, go back to the spreadsheet and select the cells you want
to apply this routine to and then press Alt+F8 and run the AddZeroes macro
from the dialog box that appears.

Rick

  #9   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5
Default adding leading zero in Excel

The alpha character will be a single character and followed by up to 3
numerals.
There is a posibility of up to 4 numerals but does not happen much. 3
numerals will be fine
I would only need the leading zeros if the numeral is from 1 - 99, for
example,
C3,C34 would be C003,C034.
There is also a comma after each item.
These are Reference Designators on a printed wiring board and are used in
the parts list for idenification.

"Rick Rothstein (MVP - VB)" wrote:

I guess we should further clarify... is the part in front of the number
always a SINGLE letter character? Is the number part always going to be
three digits long? Any other info we should know?

Rick


"ENFGDC4S" wrote in message
...
This is where my problem is. Here is an example of one of the cells:
C5,C16,C30,C38,C54,C91,C98,C136,C147
I can have a few hundred of these alpha numeric characters in one cell.
Thanks for your time.

"Gary''s Student" wrote:

That's O.K. We can solve this.

In A1 thru A3 I entered:

R1
R12
R152


I put my formula in B1 thru B3 and see:

R1 R001
R12 R012
R152 R152

What do you see?


--
Gary''s Student - gsnu200744


"ENFGDC4S" wrote:

I could not get this to work.

"Gary''s Student" wrote:

=LEFT(A1,1) & TEXT(RIGHT(A1,LEN(A1)-1),"000")

--
Gary''s Student - gsnu200744



  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,202
Default adding leading zero in Excel

Okay, see my response to Gary''s Student where the code I posted anticipated
the answer you gave.

Rick


"ENFGDC4S" wrote in message
...
The alpha character will be a single character and followed by up to 3
numerals.
There is a posibility of up to 4 numerals but does not happen much. 3
numerals will be fine
I would only need the leading zeros if the numeral is from 1 - 99, for
example,
C3,C34 would be C003,C034.
There is also a comma after each item.
These are Reference Designators on a printed wiring board and are used in
the parts list for idenification.

"Rick Rothstein (MVP - VB)" wrote:

I guess we should further clarify... is the part in front of the number
always a SINGLE letter character? Is the number part always going to be
three digits long? Any other info we should know?

Rick


"ENFGDC4S" wrote in message
...
This is where my problem is. Here is an example of one of the cells:
C5,C16,C30,C38,C54,C91,C98,C136,C147
I can have a few hundred of these alpha numeric characters in one cell.
Thanks for your time.

"Gary''s Student" wrote:

That's O.K. We can solve this.

In A1 thru A3 I entered:

R1
R12
R152


I put my formula in B1 thru B3 and see:

R1 R001
R12 R012
R152 R152

What do you see?


--
Gary''s Student - gsnu200744


"ENFGDC4S" wrote:

I could not get this to work.

"Gary''s Student" wrote:

=LEFT(A1,1) & TEXT(RIGHT(A1,LEN(A1)-1),"000")

--
Gary''s Student - gsnu200744






  #11   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 11,058
Default adding leading zero in Excel

Very nice


Thank you for introducing me to JOIN()
--
Gary''s Student - gsnu200744


"Rick Rothstein (MVP - VB)" wrote:

I can solve this with visual basic.


I'll save you the trouble.<g

If there is only one leading letter character for each "field" in the cell
and if the number part always needs to be three digits long, then this sub
should work...

Sub AddZeroes()
Dim C As Range
Dim Fields() As String
For Each C In Selection
Fields = Split(C.Value, ",")
For X = 0 To UBound(Fields)
Fields(X) = Left$(Fields(X), 1) & _
Format$(Mid$(Fields(X), 2), "000")
Next
C.Value = Join(Fields, ",")
Next
End Sub

To ENFGDC4S:
=============
All you have to do is right-click the sheet tab at the bottom, and "View
Code"; then copy/paste the above routine into the sheet's code window. Once
you have done that, go back to the spreadsheet and select the cells you want
to apply this routine to and then press Alt+F8 and run the AddZeroes macro
from the dialog box that appears.

Rick


  #12   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,202
Default adding leading zero in Excel

Thank you for introducing me to JOIN()

You are quite welcome. As the companion function to Split, it is really a
very nice function to have in the arsenal.

Rick


"Rick Rothstein (MVP - VB)" wrote:

I can solve this with visual basic.


I'll save you the trouble.<g

If there is only one leading letter character for each "field" in the
cell
and if the number part always needs to be three digits long, then this
sub
should work...

Sub AddZeroes()
Dim C As Range
Dim Fields() As String
For Each C In Selection
Fields = Split(C.Value, ",")
For X = 0 To UBound(Fields)
Fields(X) = Left$(Fields(X), 1) & _
Format$(Mid$(Fields(X), 2), "000")
Next
C.Value = Join(Fields, ",")
Next
End Sub

To ENFGDC4S:
=============
All you have to do is right-click the sheet tab at the bottom, and "View
Code"; then copy/paste the above routine into the sheet's code window.
Once
you have done that, go back to the spreadsheet and select the cells you
want
to apply this routine to and then press Alt+F8 and run the AddZeroes
macro
from the dialog box that appears.

Rick



  #13   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5
Default adding leading zero in Excel

The sub worked great! Thank you for your time and effort.
Eric

"Rick Rothstein (MVP - VB)" wrote:

Okay, see my response to Gary''s Student where the code I posted anticipated
the answer you gave.

Rick


"ENFGDC4S" wrote in message
...
The alpha character will be a single character and followed by up to 3
numerals.
There is a posibility of up to 4 numerals but does not happen much. 3
numerals will be fine
I would only need the leading zeros if the numeral is from 1 - 99, for
example,
C3,C34 would be C003,C034.
There is also a comma after each item.
These are Reference Designators on a printed wiring board and are used in
the parts list for idenification.

"Rick Rothstein (MVP - VB)" wrote:

I guess we should further clarify... is the part in front of the number
always a SINGLE letter character? Is the number part always going to be
three digits long? Any other info we should know?

Rick


"ENFGDC4S" wrote in message
...
This is where my problem is. Here is an example of one of the cells:
C5,C16,C30,C38,C54,C91,C98,C136,C147
I can have a few hundred of these alpha numeric characters in one cell.
Thanks for your time.

"Gary''s Student" wrote:

That's O.K. We can solve this.

In A1 thru A3 I entered:

R1
R12
R152


I put my formula in B1 thru B3 and see:

R1 R001
R12 R012
R152 R152

What do you see?


--
Gary''s Student - gsnu200744


"ENFGDC4S" wrote:

I could not get this to work.

"Gary''s Student" wrote:

=LEFT(A1,1) & TEXT(RIGHT(A1,LEN(A1)-1),"000")

--
Gary''s Student - gsnu200744




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
Adding a leading zero to a SSN [email protected] Excel Discussion (Misc queries) 12 March 1st 07 01:26 PM
Adding "0" as leading digits into cells in Excel Tippetue Excel Worksheet Functions 2 October 19th 06 12:14 AM
Excel Leading Zeros [email protected] Excel Discussion (Misc queries) 3 January 17th 06 06:59 PM
leading zeros in excel kiwi Excel Discussion (Misc queries) 3 May 17th 05 06:59 PM
Adding Leading Zeros to Text Jenn Excel Discussion (Misc queries) 4 January 12th 05 06:51 PM


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