Delete blank rows in a table or in a range

luolovepi

Board Regular
Joined
Jun 9, 2011
Messages
116
Does anyone can teach me how to modify the code below to allow me to delete blank rows in table "Table1" and range "Purpose"? I want to delete those blank rows from the last row until reaching a non-empty row.




</PRE>

Is it possible? Thank you!




</PRE>
Rich (BB code):
Sub DelEmptyRows()  
Dim i As Long, iLimit As Long    
iLimit = ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False  
Application.Calculation = xlCalculationManual    'pre XL97 xlManual  
For i = iLimit To 1 Step -1    
If Application.CountA(Cells(i, 1).EntireRow) = 0 Then       
Cells(i, 1).EntireRow.Delete    
End If  
Next i
Application.Calculation = xlCalculationAutomatic   
Application.ScreenUpdating = True   
iLimit = ActiveSheet.UsedRange.Rows.Count   'attempt to fix lastcell   
ActiveWorkbook.Save
End Sub


Best regards,
lolo^^




</PRE>
 
Last edited:

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Not knowing how your range "purpose" is defined I used the entire worksheet.

If your range "purpose" is actually (say) Range("A3:D46") then replace "Cells"in the 3rd line by Range("A3:D46").
Code:
Sub delblrow()
Dim purpose As Range, i&, ilimit&, c&
Set purpose = Cells
ilimit = purpose.Find("*", after:=purpose(1), searchorder:=xlByRows, _
    searchdirection:=xlPrevious).Row
c = purpose(1).Row
For i = ilimit To c Step -1
If Application.CountA(purpose.Rows(i - c)) = 0 Then
    purpose.Rows(i - c).Delete xlUp
Else
    Exit For
End If
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,815
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top