+ Reply to Thread
Results 1 to 2 of 2

Deleting blanks rows based on multiple criteria

Hybrid View

  1. #1
    Registered User
    Join Date
    10-19-2005
    Posts
    45

    Question Deleting blanks rows based on multiple criteria

    Below is a macro used to delete the entire row if a the cell in the specified column is blank.

    Can anyone suggest a way to change this macro so that it can be used to delete a row if the cells in two different columns are both blank?

    ie. If any cells are in the same row of column B and E are blank then delete that row.

    The code I have used for a single column is this:

    Sub DeleteRowOnCell()

    On Error Resume Next
    Columns("E:E").Select
    Selection.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    ActiveSheet.UsedRange

    End Sub

    Thanks in advance!!

  2. #2
    Registered User
    Join Date
    10-19-2005
    Posts
    45
    Sorry guys I have answered my own question:

    Sub DeleteRows()
    Dim theRange As Range
    Dim lastRow&, firstRow&, x&
    Set theRange = ActiveSheet.UsedRange
    lastRow = theRange.Cells(theRange.Cells.Count).Row
    firstRow = theRange.Cells(1).Row
    For x = lastRow To firstRow Step -1
    If Cells(x, 2) = "" And Cells(x, 5) = "" Then
    Rows(x).Delete
    End If
    Next
    End Sub

+ 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