+ Reply to Thread
Results 1 to 7 of 7

Concatenating a zero

  1. #1
    Forum Contributor
    Join Date
    08-20-2005
    Posts
    171

    Concatenating a zero

    Hi,

    Writiing a macro which goes through each cell 9they are numbers) in column 5, if the length of the cell is 1 a zero is added to the start.
    Below is an excerpt of the code, not quite working, many thks

    Dim i
    lastrow = Range("A50000").End(xlUp).Row
    For i = 1 To lastrow
    If Len(Cells(i, 5)) = 1 Then
    Cells(i, 5) = "0" & Cells(i, 5)
    End If
    Next

  2. #2
    Forum Contributor
    Join Date
    12-04-2003
    Posts
    360
    Sub sdfsdf()
    Dim i
    lastrow = Range("A50000").End(xlUp).Row
    For i = 1 To lastrow
    If Len(CStr(Cells(i, 1))) = 1 Then
    Cells(i, 1).NumberFormat = "@"
    Cells(i, 1) = CStr("0" & Cells(i, 1))
    End If
    Next
    End Sub

  3. #3
    Forum Contributor
    Join Date
    08-20-2005
    Posts
    171
    Thanks a lot Matt

  4. #4
    Forum Contributor
    Join Date
    08-20-2005
    Posts
    171

    |Thks

    Thanks a lot Matt

  5. #5
    Forum Contributor
    Join Date
    08-20-2005
    Posts
    171

    |Thks

    Thanks a lot Matt

  6. #6
    Forum Contributor
    Join Date
    08-20-2005
    Posts
    171

    |Thks

    Thanks a lot Matt

  7. #7
    Gary Keramidas
    Guest

    Re: Concatenating a zero

    this worked for me

    Sub test()
    Dim i
    Dim lastrow As Long
    lastrow = Range("A50000").End(xlUp).Row
    For i = 1 To lastrow
    If Len(Cells(i, 5)) = 1 Then
    Cells(i, 5).Value = "0" & Cells(i, 5).Value
    End If
    Next

    End Sub

    --


    Gary


    "T De Villiers" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > Hi,
    >
    > Writiing a macro which goes through each cell 9they are numbers) in
    > column 5, if the length of the cell is 1 a zero is added to the start.
    >
    > Below is an excerpt of the code, not quite working, many thks
    >
    > Dim i
    > lastrow = Range("A50000").End(xlUp).Row
    > For i = 1 To lastrow
    > If Len(Cells(i, 5)) = 1 Then
    > Cells(i, 5) = "0" & Cells(i, 5)
    > End If
    > Next
    >
    >
    > --
    > T De Villiers
    > ------------------------------------------------------------------------
    > T De Villiers's Profile:
    > http://www.excelforum.com/member.php...o&userid=26479
    > View this thread: http://www.excelforum.com/showthread...hreadid=563715
    >




+ 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