View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Ryan H Ryan H is offline
external usenet poster
 
Posts: 489
Default Selecting Blank Cells then deleting those rows

You would have to modify the code to a For...Next Loop instead of a For Each
Loop. I wrote two different ways to delete empty rows. You can decide which
you prefer.

OPTIOIN 1:

Sub DeleteRows1()

Dim lngFirstRow As Long
Dim lngLastRow As Long
Dim i As Long

lngFirstRow = 1
lngLastRow = Cells(Rows.Count, "D").End(xlUp).Row

For i = lngLastRow To lngFirstRow Step -1
If Cells(i, "D") = "" Then
Rows(i).Delete SHift:=xlUp
End If
Next i

End Sub


OPTION 2:

Sub DeleteRows2()

Dim lngFirstRow As Long
Dim lngLastRow As Long

lngFirstRow = 1
lngLastRow = Cells(Rows.Count, "D").End(xlUp).Row

With Sheets("Sheet1")
.Range(.Cells(lngFirstRow, "D"), .Cells(lngLastRow, "D")). _
SpecialCells(xlCellTypeBlanks).EntireRow.Delete SHift:=xlUp
End With

End Sub


Hope this helps! If so, let me know, click "YES" below.
--
Cheers,
Ryan


"Mikey" wrote:

Ryan responded with this code to highlight the cells. What code would delete
the rows?
------------------------
So you just want to "Select" the cell? Use this,

Sub Highlighter()

Dim lngLastRow As Long
Dim rng As Range

lngLastRow = Cells(Rows.Count, "D").End(xlUp).Row

For Each rng In Range("D1:D" & lngLastRow)
If IsEmpty(rng) Then
rng.Select
Exit For
End If
Next rng

End Sub
--
Cheers,
Ryan


--
Mickey