View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default Selecting a range to delete

You are correct to be concerned. You need to tell the AutoFilter to cover
the entire range including any embedded blank cells. In the code below:

1. rG is set to cover the portion of column G that should be examined
2. the filter is applied to the ENTIRE column
3. we use SpecialCells to locate the visible cells in the filtered data
4. we delete the rows containing the visible cells
5. we cleanup by removing the filter

Sub RowKiller()
'
' gsnuxx
'
Dim rVis As Range, n As Long
Dim rG As Range
n = Cells(Rows.Count, "G").End(xlUp).Row
Set rG = Range("G2:G" & n)
Columns("G:G").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="Alt"
Set rVis = Intersect(rG, ActiveSheet.Cells.SpecialCells(xlCellTypeVisible))
rVis.EntireRow.Delete
Range("G1").Select
Selection.AutoFilter
End Sub

--
Gary''s Student - gsnu200902


"John Keith" wrote:

On Sat, 5 Sep 2009 13:22:02 -0700, Gary''s Student
wrote:

1. turn on AutoFIlter on column G
2. select the rows containing "Alt"
3. delete the visible rows

This can be done easily either manually or with VBA.


Gary's Student,

I thought about this but I did not try it because the data set has
numerous locations with blank cells and I think the autofilter might
stop before all the rows are filtered. Am I wrong or is there some way
to overcome this limitation?

Thanks



John Keith