View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Ocmulgee Ocmulgee is offline
external usenet poster
 
Posts: 3
Default finding empty rows and deleting

I've found that it's faster in Excel to insert a numbered column,
then sort the data column to drive empty rows to bottom of table,
then delete empty rows and rearrange the table back to the original order.
This is faster than walking the table (with code), finding blank rows and
deleting one at a time.

The following assumes your table starts in a1, adjust address values if your
column has header

Sub DeleteEmptyRows()
'insert new column 'a' and number it sequentially for sorting
Columns("A:A").Insert Shift:=xlToRight
Range("A1").FormulaR1C1 = "1"
Range("A2").FormulaR1C1 = "2"
Range("A3").FormulaR1C1 = "3"
Set StartRange1 = Range("a3")
Set EndRange1 = Range("B65536").End(xlUp).Offset(0, -1)
Range(StartRange1, EndRange1).DataSeries Rowcol:=xlColumns,
Type:=xlLinear, Date:=xlDay, Step:=1, Trend:=False
'sort by column 'B' to drive empty rows to bottom of column
Range("B1").Sort Key1:=Range("B1"), Order1:=xlAscending,
Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom
'delete empty rows
Set StartRange2 = Range("b1").End(xlDown).Offset(1, -1)
Set EndRange2 = Range("A65536").End(xlUp)
Range(StartRange2, EndRange2).EntireRow.Delete
'sort again by column 'A' to restore original order
Range("A1").Sort Key1:=Range("A1"), Order1:=xlAscending,
Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom
'delete column 'A'
Columns("A:A").Delete
End Sub

hope this helps

"Ryan" wrote in message
...
I have range of data that varies. The data has empty rows of data. I need

to find the empty rows and delete them. Need help creating VBA code to do
this.