+ Reply to Thread
Results 1 to 3 of 3

Replacing the 0 by "" in each line until value <> 0

Hybrid View

  1. #1
    Registered User
    Join Date
    08-17-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    31

    Question Replacing the 0 by "" in each line until value <> 0

    Hello,

    I am puzzled with this one.

    I have sheet with numerous columns.
    Col A - Col B - Col C - Col D - etc
    SKU1 - 0 - 0 - 125
    SKU2 - 12 - 0 - 14
    SKU3 - 0 - 56 - 0
    SKU4 - 0 - 0 - 1

    I would like to replace all the 0 in a row, starting from the left UNTIL I encounter a value so the above would become (I entered "" where I would like to remove the 0)
    Col A - Col B - Col C - Col D - etc
    SKU1 - "" - "" - 125
    SKU2 - 12 - 0 - 14
    SKU3 - "" - 56 - 0
    SKU4 - "" - "" - 1

    Any idea on how to tackle this one? I am puzzled :/

    Thanks in advance
    Ludo
    Last edited by Coume; 03-15-2010 at 11:03 AM.

  2. #2
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    Re: Replacing the 0 by "" in each line until value <> 0

    Simplist is to use a very simple piece of code:

    Select the range and run
    Sub replace()
    
    Dim ColCounter As Long, RowCounter As Long
    
    For RowCounter = 1 To Selection.Rows.Count
      For ColCounter = 1 To Selection.Columns.Count
        If Cells(RowCounter, ColCounter) = 0 Then
          Cells(RowCounter, ColCounter) = ""
        ElseIf Application.WorksheetFunction.IsNumber(Cells(RowCounter, ColCounter)) Then
          Exit For
        End If
      Next ColCounter
    Next RowCounter
    
    End Sub
    Last edited by rwgrietveld; 03-15-2010 at 10:41 AM.
    Looking for great solutions but hate waiting?
    Seach this Forum through Google

    www.Google.com
    (e.g. +multiple +IF site:excelforum.com/excel-general/ )

    www.Google.com
    (e.g. +fill +combobox site:excelforum.com/excel-programming/ )

    Ave,
    Ricardo

  3. #3
    Registered User
    Join Date
    08-17-2009
    Location
    England
    MS-Off Ver
    Excel 2003
    Posts
    31

    Re: Replacing the 0 by "" in each line until value <> 0

    Thanks a lot!

    I was expecting a pointer and not the working macro that quickly.

    Works perfectly.

+ 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