+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: Adding 0 to the end of selected cells

  1. #1
    Registered User
    Join Date
    12-15-2010
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    6

    Adding 0 to the end of selected cells

    Hello all,

    I need some help with this probably very simple macro. I get an excel sheet with data that is made up of 5 digits. However i need to change this to 6 digits by adding a 0 at the end. The data is contained in two seperate colums. I have uploaded an example of the data. Column A is not important and can be ignored. The data in columns B and C needs to be converted into the 6 digits with trailing 0.

    I have searched around the internet and got thrown from one site to the next with possible solutions but nothing that really does what i want. It's probably out there somewhere i just cant find it.

    Any help with this will be greatly appreciated.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor scottylad2's Avatar
    Join Date
    09-03-2010
    Location
    edinburgh
    MS-Off Ver
    Office 2007 Prof & Office 2010 Student Edition
    Posts
    617

    Re: Adding 0 to the end of selected cells

    can't you just multiply your values by 10?
    Windows 7 using Office 2007 & 2010

    Remember your [ code ] [ /code ] tags, makes reading soooo much easier

  3. #3
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,276

    Re: Adding 0 to the end of selected cells

    Hi and welcome to the forum. Upon looking at your example, your numbers are formatted as text, they need to be converted to a number format. Once there you can run this code:
    Range("B2:C14").NumberFormat = "0.000"
    As for a macro to convert to a number format? I don't know and recording wouldn't make me any wiser on the matter.
    Please leave a message after the beep!

  4. #4
    Valued Forum Contributor scottylad2's Avatar
    Join Date
    09-03-2010
    Location
    edinburgh
    MS-Off Ver
    Office 2007 Prof & Office 2010 Student Edition
    Posts
    617

    Re: Adding 0 to the end of selected cells

    just looked at your sample....is what you have already text? you could have B3&0 and that will add a trailing 0 if the value you pull into B3 is from another formula, then tag the &0 onto the end of that
    Windows 7 using Office 2007 & 2010

    Remember your [ code ] [ /code ] tags, makes reading soooo much easier

  5. #5
    Registered User
    Join Date
    12-15-2010
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Adding 0 to the end of selected cells

    Thanks for the help!

    I was playing around with the suggestions you gave. When i convert the format to a number and run the command you gave nothing happens. This is the complete code:

    Sub Add0()
    Range("B2:C14").NumberFormat = "0.000"
    End Sub

    I dont get any error messages so it seems to run however nothing is changed.

    I actually came across another problem. There is a dot in the value as well that needs to be removed to be able to import the data correctly into another excel sheet.
    I also tried it with the formula and that seems to work. However that still doesnt remove the dot.

  6. #6
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,276

    Re: Adding 0 to the end of selected cells

    sorry, try this:
    Worksheets("Blad1").Range("B2:C14").NumberFormat = "0.000"
    Please leave a message after the beep!

  7. #7
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,276

    Re: Adding 0 to the end of selected cells

    By the way, please use code tags around your code, it makes code easier to see and work with.
    Please leave a message after the beep!

  8. #8
    Forum Guru Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,276

    Re: Adding 0 to the end of selected cells

    And the only dot I see is the decimal point. Is that what you are talking about?
    Please leave a message after the beep!

  9. #9
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    537

    Re: Adding 0 to the end of selected cells

    Quote Originally Posted by own4utreg View Post
    Hello all,

    data that is made up of 5 digits. However i need to change this to 6 digits by adding a 0 at the end.
    See if this helps,
    I added columns D and E with the 0 added to the end.
    Attached Files Attached Files

  10. #10
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Adding 0 to the end of selected cells

    Sub snb()
      [B1:C14] = [B1:C14 & "0"]
    End Sub



  11. #11
    Registered User
    Join Date
    12-15-2010
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Adding 0 to the end of selected cells

    Quote Originally Posted by snb View Post
    Sub snb()
      [B1:C14] = [B1:C14 & "0"]
    End Sub
    The only way i can get this macro to change anything is when i change the format to a number with 3 decimals. If this is the way to go then thats not a problem. However after that i need to paste the info into another excel sheet which requires the numbers to be without any dots or comma's.

    So i think were slowly getting there

    Thanks again so far!

  12. #12
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    537

    Re: Adding 0 to the end of selected cells

    Quote Originally Posted by jwright650 View Post
    See if this helps,
    I added columns D and E with the 0 added to the end.
    Did this work for you?

    Here is a preview from the worksheet:
    Quote Originally Posted by snippet from WorkSheet

    164.440
    485.550

  13. #13
    Registered User
    Join Date
    12-15-2010
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Adding 0 to the end of selected cells

    I figured out how to get this to work thanks to all your tips. I combined some of the things you guys mentioned and used this to record a macro in excel. I inserted some colums and used a formula to take the first 3 and last 2 digits of the value and added a 0 at the end. This way i got rid of the comma in between.

    For those interested here is the macro that was recorded. Maybe there's some stuff in there thats not really needed but it works and thats whats important right now.

    Sub Aanpassen_RD_download()
    '
    ' Aanpassen_RD_download Macro
    '
    ' Sneltoets: Ctrl+n
    '
        Columns("C:C").Select
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
        Columns("E:E").Select
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
        Range("C2").Select
        ActiveCell.FormulaR1C1 = "=MID(RC[-1],1,3)&MID(RC[-1],5,2)&""0"""
        Range("C2").Select
        Selection.AutoFill Destination:=Range("C2:C52"), Type:=xlFillDefault
        Range("C2:C52").Select
        ActiveWindow.SmallScroll Down:=-60
        Range("E2").Select
        ActiveCell.FormulaR1C1 = "=MID(RC[-1],1,3)&MID(RC[-1],5,2)&""0"""
        Range("E2").Select
        Selection.AutoFill Destination:=Range("E2:E52"), Type:=xlFillDefault
        Range("E2:E52").Select
        ActiveWindow.SmallScroll Down:=-39
    End Sub
    Thanks a lot to all the people that helped! As i mentioned before i took some things and combined them so you all helped me solve this problem. You have my gratitude.

  14. #14
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    537

    Re: Adding 0 to the end of selected cells

    Quote Originally Posted by own4utreg View Post
    I figured out how to get this to work
    Good stuff, thanks for posting your results.....


    Note to self: <take down notes for future reference>

  15. #15
    Registered User
    Join Date
    12-15-2010
    Location
    Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Adding 0 to the end of selected cells

    Taking notes is always a good thing!

+ 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.2.0