+ Reply to Thread
Results 1 to 6 of 6

Format a number in VBA : 1 --> 001

Hybrid View

floep Format a number in VBA : 1... 10-22-2006, 08:10 AM
oldchippy Custom Format 000 10-22-2006, 08:16 AM
floep Thx for the answer. Got... 10-22-2006, 08:35 AM
oldchippy Hi Floep, When you get the... 10-22-2006, 08:44 AM
antoka05 Format Number 10-22-2006, 04:47 PM
Mallycat The other thing you could do... 10-23-2006, 04:15 AM
  1. #1
    Registered User
    Join Date
    07-27-2006
    Posts
    23

    Format a number in VBA : 1 --> 001

    Hi Guys,

    How can I format a number in VBA ? For example I want to turn 1 in 001.

    Thx,
    Floep

  2. #2
    Forum Expert oldchippy's Avatar
    Join Date
    02-14-2005
    Location
    Worcester, UK
    MS-Off Ver
    Excel 2007 (Home)
    Posts
    7,097
    Quote Originally Posted by floep
    Hi Guys,

    How can I format a number in VBA ? For example I want to turn 1 in 001.

    Thx,
    Floep
    Custom Format 000

  3. #3
    Registered User
    Join Date
    07-27-2006
    Posts
    23
    Thx for the answer. Got another problem now. When I use the formatted result (0001) in a formula it changes back to its original format (1). For example I use a concatenation with the values 'T' and '0001' and I get 'T1' as a result although I need 'T0001'. This is just a simple example of the concatination, the the actual concatenation is much more complex and it is not possible to format the result of the concatenation. I there a way I can use the 0001 value in the concatenation ?

    Floep

  4. #4
    Forum Expert oldchippy's Avatar
    Join Date
    02-14-2005
    Location
    Worcester, UK
    MS-Off Ver
    Excel 2007 (Home)
    Posts
    7,097
    Quote Originally Posted by floep
    Thx for the answer. Got another problem now. When I use the formatted result (0001) in a formula it changes back to its original format (1). For example I use a concatenation with the values 'T' and '0001' and I get 'T1' as a result although I need 'T0001'. This is just a simple example of the concatination, the the actual concatenation is much more complex and it is not possible to format the result of the concatenation. I there a way I can use the 0001 value in the concatenation ?

    Floep
    Hi Floep,

    When you get the formatted result 0001, can't you then copy and then format to text

  5. #5
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Format Number

    In vba you can do so:
    myCell = range("a1") 'the celle where is a number, for instance 1
    range("b1") = format(myCell,"0000") ' you will have 0001 in cell B1

    if you want to use also 'T' as prefix you can do:
    range("b1") = "T" & format(myCell,"0000") ' you will have T0001 in cell B1

    In Excel you can do so:
    ="T" & text(a1;"0000") and you will be have 'T0001

    Rgards,
    Antonio

  6. #6
    Valued Forum Contributor
    Join Date
    06-16-2006
    Location
    Sydney, Australia
    MS-Off Ver
    2013 64bit
    Posts
    1,394
    The other thing you could do is set the variable to be text rather than an integer, that way any formatting you apply will stick.

    Matt

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1