Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Pad with leading zeros?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Pad with leading zeros?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 196
Default Pad with leading zeros?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Pad with leading zeros?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Pad with leading zeros?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Pad with leading zeros?

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
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
Leading Zeros [email protected] Excel Discussion (Misc queries) 6 August 3rd 06 06:15 PM
add leading zeros Jacqueline Excel Worksheet Functions 2 July 12th 06 06:46 PM
Leading Zeros Karen Excel Discussion (Misc queries) 3 January 10th 06 09:50 PM
Leading zeros Paul Excel Discussion (Misc queries) 4 June 12th 05 04:04 AM
save text field w/ leading zeros in .csv format & not lose zeros? Ques Excel Discussion (Misc queries) 1 May 4th 05 06:21 PM


All times are GMT +1. The time now is 11:23 AM.

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"