Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional Delete

Status
Not open for further replies.

pebrown

Technical User
Jul 30, 2003
1
US
I need help writing a macro to remove rows from a large spreadsheet where the cells in columns E# - AI is blank. All 31 cells on the row must be blank before the entire
row can be removed. Columns A# - D# will always have
values. The spreadsheet has approximately 2300 rows to
search.
 
Here is one way:
[blue]
Code:
Sub demo()
  DeleteBlankDataRows "E", "AI"
End Sub

Sub DeleteBlankDataRows(FromColumn As String, ThruColumn As String)
Dim nFirstRow As Long
Dim nLastRow As Long
Dim nRow As Long
Dim sAddress As String
Dim rng As Range
  With ActiveSheet.UsedRange
    nLastRow = .Rows.Count + .Row - 1
    nFirstRow = .Row
  End With
  Application.ScreenUpdating = False
  For nRow = nLastRow To nFirstRow Step -1
    sAddress = FromColumn & nRow & ":" & ThruColumn & nRow
    Set rng = Range(sAddress)
    If WorksheetFunction.CountBlank(rng) = rng.Count Then
      rng.EntireRow.Delete
    End If
  Next nRow
  Application.ScreenUpdating = True
End Sub
[/color]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top