Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default "000" reverts back to "0" even with a string

I want to have a 4 digit number in all cases but some have 0 thru 3.

This is how I attempted to solve it:

dim x(3) as string
x(1)=234
x(2)=67
x(3)=5
If Len(x(m)) = 1 Then x(m) = 000 & x(m)
If Len(x(m)) = 1 Then x(m) = 00 & x(m)
If Len(x(m)) = 1 Then x(m) = 0 & x(m)
the problem is when you enter "000" in for the result it automatically
reverts back to "0"
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default "000" reverts back to "0" even with a string


They ain't strings until you make them strings...
If Len(x(m)) = 1 Then x(m) = "000" & x(m)
If Len(x(m)) = 1 Then x(m) = "00" & x(m)
If Len(x(m)) = 1 Then x(m) = "0" & x(m)
--
Jim Cone
Portland, Oregon USA
( http://www.mediafire.com/PrimitiveSoftware )




"Philosophaie"
wrote in message ...
I want to have a 4 digit number in all cases but some have 0 thru 3.
This is how I attempted to solve it:

dim x(3) as string
x(1)=234
x(2)=67
x(3)=5
If Len(x(m)) = 1 Then x(m) = 000 & x(m)
If Len(x(m)) = 1 Then x(m) = 00 & x(m)
If Len(x(m)) = 1 Then x(m) = 0 & x(m)
the problem is when you enter "000" in for the result it automatically
reverts back to "0"
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default "000" reverts back to "0" even with a string

Don't use a series of If..Then tests (by the way, the numbers you are
testing against should be 1, 2, 3 and not 1, 1, 1), use the Format function
instead. For all your cases, use this single statement...

x(m) = Format(x(m), "0000")

--
Rick (MVP - Excel)



"Philosophaie" wrote in message
...
I want to have a 4 digit number in all cases but some have 0 thru 3.

This is how I attempted to solve it:

dim x(3) as string
x(1)=234
x(2)=67
x(3)=5
If Len(x(m)) = 1 Then x(m) = 000 & x(m)
If Len(x(m)) = 1 Then x(m) = 00 & x(m)
If Len(x(m)) = 1 Then x(m) = 0 & x(m)
the problem is when you enter "000" in for the result it automatically
reverts back to "0"


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
Converting "uppercase" string data to "lower case" in CSV file [email protected] Excel Discussion (Misc queries) 2 August 12th 08 08:36 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM


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