Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22
Default Change a 1,2,3 or 4 digit number to a 6 character text string

Hi, I have a file that has a column with either 1,2,3 or 4 digit numbers. I
need to convert that value to a 4 digit number and add '02 to the front of
it. For example if A1 = 34 I would like B1 to be equal to '020034, if A1 =
134 then B1 should be '020134. Here is the formula I tried to use but it
keeps converting the number into a text string. How can I make this work?

=IF(FIXED(LEFT(A1,4),0)<10,"02000" &
LEFT(A1,1),IF(FIXED(LEFT(A1,4),0)<100,"0200" &
LEFT(A1,2),IF(FIXED(LEFT(A1,4),0)<1000,"020" & LEFT(A1,3),"02" & LEFT(A1,4))))

--
Thank You,
Steve
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,311
Default Change a 1,2,3 or 4 digit number to a 6 character text string

One way,

="02"&REPT(0,6-(LEN(A1)+2))&A1

Note, this will remain as text and not a number. This is necessary to
maintain the zero at the beginning. Otherwise, you'd have to change the
cell formatting.

=INT(2 & REPT(0,6-(LEN(A1)+2))&A1)

Change cell format to 000000

HTH,
Paul

--

"Steve D" wrote in message
...
Hi, I have a file that has a column with either 1,2,3 or 4 digit numbers.
I
need to convert that value to a 4 digit number and add '02 to the front of
it. For example if A1 = 34 I would like B1 to be equal to '020034, if A1 =
134 then B1 should be '020134. Here is the formula I tried to use but it
keeps converting the number into a text string. How can I make this work?

=IF(FIXED(LEFT(A1,4),0)<10,"02000" &
LEFT(A1,1),IF(FIXED(LEFT(A1,4),0)<100,"0200" &
LEFT(A1,2),IF(FIXED(LEFT(A1,4),0)<1000,"020" & LEFT(A1,3),"02" &
LEFT(A1,4))))

--
Thank You,
Steve



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,069
Default Change a 1,2,3 or 4 digit number to a 6 character text string

If your column has actual numbers, you can simplify your formula:
=IF(A1<10,"02000" & A1,IF(A1<100,"0200" &A1,IF(A1<1000,"020" & A1,"02" & A1)))

This gives the desired output as text, because you are concatenating the
text "02" with the number in column A. If you want an actual number in column
B as your output, but that shows the inital zero, you can do it this way:
- Your formula in B1 would be =20000+A1
- Copy B1 down as needed
- Select the cells in column B and format them to show the inital zero.
Select Format Cells Custom. In the Type box, enter 000000

Hope this helps,

Hutch

"Steve D" wrote:

Hi, I have a file that has a column with either 1,2,3 or 4 digit numbers. I
need to convert that value to a 4 digit number and add '02 to the front of
it. For example if A1 = 34 I would like B1 to be equal to '020034, if A1 =
134 then B1 should be '020134. Here is the formula I tried to use but it
keeps converting the number into a text string. How can I make this work?

=IF(FIXED(LEFT(A1,4),0)<10,"02000" &
LEFT(A1,1),IF(FIXED(LEFT(A1,4),0)<100,"0200" &
LEFT(A1,2),IF(FIXED(LEFT(A1,4),0)<1000,"020" & LEFT(A1,3),"02" & LEFT(A1,4))))

--
Thank You,
Steve

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,856
Default Change a 1,2,3 or 4 digit number to a 6 character text string

One way:

="02"&TEXT(A1,"0000")

Copy down as required.

Hope this helps.

Pete

On Mar 28, 7:41*pm, Steve D wrote:
Hi, I have a file that has a column with either 1,2,3 or 4 digit numbers. I
need to convert that value to a 4 digit number and add '02 to the front of
it. For example if A1 = 34 I would like B1 to be equal to '020034, if A1 =
134 then B1 should be '020134. Here is the formula I tried to use but it
keeps converting the number into a text string. How can I make this work?

=IF(FIXED(LEFT(A1,4),0)<10,"02000" &
LEFT(A1,1),IF(FIXED(LEFT(A1,4),0)<100,"0200" &
LEFT(A1,2),IF(FIXED(LEFT(A1,4),0)<1000,"020" & LEFT(A1,3),"02" & LEFT(A1,4))))

--
Thank You,
Steve


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
Change 3 letter text string to a number string Pete Excel Discussion (Misc queries) 3 December 31st 07 07:47 PM
Excel-Match 1st text character in a string to a known character? bushlite Excel Worksheet Functions 2 January 15th 07 06:36 PM
Counting number of time a character appears in a string Henrik Excel Worksheet Functions 5 October 20th 05 11:00 PM
want to remove all text characters equal to one character in length from text string [email protected] Excel Worksheet Functions 1 April 18th 05 09:56 PM
want to remove all text characters equal to one character in length from text string [email protected] Excel Worksheet Functions 1 April 18th 05 12:25 AM


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