+ Reply to Thread
Results 1 to 2 of 2

VBA - removing last digits in excel , beginner

Hybrid View

  1. #1
    Registered User
    Join Date
    10-20-2011
    Location
    Bratislava
    MS-Off Ver
    Excel 2007
    Posts
    1

    VBA - removing last digits in excel , beginner

    Hello,

    I have never used VBA before, so please go easy on me.

    I would like to go through list of asset numbers and if any number ends with one or more zeroes, I would like them removed.

    I have drafted something like:


    Sub Remove_Zeros()
    
    If
    Right(Cell(3, 3), 1) = 0
    
    Do
    
    Left(Cell(3,3), Len(Cell(3,3)-1))
    
    Loop While Right(Cell(3, 3), 1) = 0
    
    
    End If
    
    End Sub
    Please check my syntax and logical process for any errors.
    Last edited by pike; 10-20-2011 at 05:29 AM. Reason: add code tags for newbie

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,322

    Re: VBA - removing last digits in excel , beginner

    Almost.

    Select the cells before running the macro.

    Sub Remove_Zeros()
    
    Dim cell As Range
    
    For Each cell In Selection
        Do While Right(cell, 1) = 0
            cell = Left(cell, Len(cell) - 1)
        Loop
    Next ' cell
    
    End Sub

    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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