View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Barb Reinhardt Barb Reinhardt is offline
external usenet poster
 
Posts: 3,355
Default Pls help: macro to delete empty rows

Dim cell As Range
For Each cell In Range("1:1144") 'You're looking at all cells in rows
1:1144.
If cell = "" Then
cell.Rows.Delete shift:=xlUp
End If
Next

Try this

Dim myRange as range
dim myCell as range
set myRange = Range("A1:A100") 'or whatever you want

Dim myDeleteRange as range

for each myCell in myRange
if Isempty(mycell) then
if myDeleteRange is nothing then
Set myDeleteRange = myCell
else
Set myDeleteRange = union(mydeleterange,mycell)
end if
end if

next mycell

If not myDeleteRange is nothing then
myDeleteRange.entireRow.delete
end if

Untested ... (just typed in here)
--


HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



" wrote:

I have a worksheet with over 1100 rows, but with data only in every
few rows. The other rows are "empty" (ISBLANK is true). I need a
macro to delete the empty rows.

Using Record Macro, I see that if I select a row and right-click
Delete, the logic is:

Rows("2:2").Select
Selection.Delete shift:=xlUp

So in my ignorance, I tried the following, to no avail:

Dim cell As Range
For Each cell In Range("1:1144")
If cell = "" Then
cell.Rows.Delete shift:=xlUp
End If
Next

So how can I do this?

PS: Also, I forgot how to turn off/on the worksheet update. And if
I need to do this iteratively, as above, I would like to go from the
bottom up so that the shift xlUp is more efficient.

Many thanks.