Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a string that's made up of concatenating other variables together,
one of which is a numerical value. I want to put leading zeros on the numeric value, up to a full string length of 3. Ex: A = Y (string) B = 1234 (string) C = 1 (numeric) A B C Final string would look like this: Y1234.001 Help??? Thanks! Shawn |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Shawn,
Is this what you are looking for, or are you looking for something VBA-related? =A1&A2&TEXT(A3/1000,".000") -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] 43fan wrote: I have a string that's made up of concatenating other variables together, one of which is a numerical value. I want to put leading zeros on the numeric value, up to a full string length of 3. Ex: A = Y (string) B = 1234 (string) C = 1 (numeric) A B C Final string would look like this: Y1234.001 Help??? Thanks! Shawn |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Format(C,"000")
-----Original Message----- Ex: A = Y (string) B = 1234 (string) C = 1 (numeric) A B C Final string would look like this: Y1234.001 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Jake,
Thanks for the quick reply, but yes, something VBA related. I'm printing a heading on a report that will be the concatenation of several fields like I said, and one of those fields needs to have leading zeroes. I'm wondering though, could I use something like this? newvar = A + B + str(C/1000)? C is always an integer, rarely goes higher than 4, occasionally to 6, but I suppose could go as high as 15-20, but that would still end up with it being ..020 once divided by 1000. Would the str() function convert that to ".020"? Gonna give it a try and see what happens. :) Thanks again! "Jake Marx" wrote in message ... Hi Shawn, Is this what you are looking for, or are you looking for something VBA-related? =A1&A2&TEXT(A3/1000,".000") -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] 43fan wrote: I have a string that's made up of concatenating other variables together, one of which is a numerical value. I want to put leading zeros on the numeric value, up to a full string length of 3. Ex: A = Y (string) B = 1234 (string) C = 1 (numeric) A B C Final string would look like this: Y1234.001 Help??? Thanks! Shawn |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
43fan wrote:
Thanks for the quick reply, but yes, something VBA related. I'm printing a heading on a report that will be the concatenation of several fields like I said, and one of those fields needs to have leading zeroes. I'm wondering though, could I use something like this? newvar = A + B + str(C/1000)? When concatenating Strings, you should use the & operator. The Str function will work, but Format gives you more control over the output. As Mark suggested, you can use the Format function: Dim sNewVar As String sNewVar = Range("A1").Value & Range("A2").Value & _ Format$(Range("A3").Value/1000, ".000") -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Jake,
I agree you should use & for annotation, but + works. -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Jake Marx" wrote in message ... 43fan wrote: Thanks for the quick reply, but yes, something VBA related. I'm printing a heading on a report that will be the concatenation of several fields like I said, and one of those fields needs to have leading zeroes. I'm wondering though, could I use something like this? newvar = A + B + str(C/1000)? When concatenating Strings, you should use the & operator. The Str function will work, but Format gives you more control over the output. As Mark suggested, you can use the Format function: Dim sNewVar As String sNewVar = Range("A1").Value & Range("A2").Value & _ Format$(Range("A3").Value/1000, ".000") -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Leading Zeros | Excel Discussion (Misc queries) | |||
add leading zeros | Excel Worksheet Functions | |||
Leading Zeros | Excel Discussion (Misc queries) | |||
Leading zeros | Excel Discussion (Misc queries) | |||
save text field w/ leading zeros in .csv format & not lose zeros? | Excel Discussion (Misc queries) |