+ Reply to Thread
Results 1 to 9 of 9

Adding 0's before a text to make it 6 characters long

  1. #1
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Adding 0's before a text to make it 6 characters long

    Hi guys

    As we use the following line of code to change the column to number format with two decimals in it. Can anyone please tell me how to change the column to text format with 6 characters in it and if it is less than 6 characters then add 0's in front of it.
    Please Login or Register  to view this content.
    Last edited by aman1234; 09-21-2010 at 05:38 AM.

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Adding 0's before a text to make it 6 characted long

    I use this to convert numbers:

    Please Login or Register  to view this content.
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Adding 0's before a text to make it 6 characted long

    Hi

    Please find below the code that copies the selected date data from sheet1 to sheet2. The column B in sheet1 has text datatype so whenver in the textbox in userform the user types 001091 then in the cell in column B it appears the same but when I write the following code to copy the certain date data from sheet1 to sheet2 then in sheet2 the column B trims all 0's before any number text so in sheet2 the cell in column B stores value like 1091.
    Please Login or Register  to view this content.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Adding 0's before a text to make it 6 characted long

    Please Login or Register  to view this content.



  5. #5
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Adding 0's before a text to make it 6 characters long

    Hi

    I tried it but it didn't work. In sheet1 the column B stores everything right (that means 6 characters always" but when some data is copied from sheet 1 to sheet2 then the column B in sheet2 doesn't store the leading 0's. How can I change the column B in sheet2 so that if the text is less than 6 characters then place 0's before it to make it 7 characters long.or before printing the sheet2 how can we format column B.

    Please suggest me.

    Thanks

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Adding 0's before a text to make it 6 characters long

    Did you test my suggestion ?

  7. #7
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Adding 0's before a text to make it 6 characters long

    Hi snb

    If I make changes to one cell then the code works fine but I have a whole column and I want to change the format of the whole column . Could you please help me in that. If I write the following code then it doesn't work.
    Please Login or Register  to view this content.
    Thanks

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Adding 0's before a text to make it 6 characters long

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    883

    Re: Adding 0's before a text to make it 6 characters long

    Thanks a lot snb for your help. It worked perfectly fine.

+ 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