Results 1 to 2 of 2

Delete rows based on value in cells

Threaded View

  1. #1
    Registered User
    Join Date
    01-26-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    1

    Smile Delete rows based on value in cells

    Hi,

    In the code below I want to check if the cell in column J contains 0 (zero). If it does I want to delete the corresponding row. I want to put this in loop so that it checks the entire sheet for this condition and deletes rows where ever the value in cell (row, J) = 0. The problem is that the code below only deletes one row and does not go back in the loop to check for other cells in column J. My data starts from row 4.

    Any help is greatly appreciated.

    Sub test()

    Dim lastrow As Long
    Dim i As Long

    Sheets("Sheet1").Select

    lastrow = Worksheets("Sheet1").Range("J4").End(xlDown).Row

    For i = lastrow To 4 Step -1
    If Sheets("Sheet1").Cells(i, "J") = 0 Then
    Sheets("Sheet1").Cells(i, "J").EntireRow.Delete shift:=xlUp
    ' Exit For
    End If

    Next i

    End Sub
    Last edited by dws123; 01-26-2010 at 06:54 PM.

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