Delete blank rows

tlindeman

Active Member
Joined
Jun 29, 2005
Messages
313
I have a column A, on sheet called SHEET2 Could you please provide me with simple VBA that deletes all rows where there is no data in columnA. My rows are from A1:A2941.

THank You
Tony
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Something I use:
Code:
Sub DeleteVisibleRows()
 
Dim i As Long, j As Long
With Application
    .ScreenUpdating = False
    .DisplayAlerts = False
End With
With Sheets("Sheet2")
    If .AutoFilterMode Then .AutoFilterMode = False
    i = Application.Max(2941, .Range("A" & Rows.Count).End(xlUp).row)
    j = .Cells(1, Columns.Count).End(xlToLeft).Column
    With .Range("A1", Cells(i, j))
        .AutoFilter
        .AutoFilter Field:=1, Criteria1:="="
    End With
    .UsedRange.Offset(1, 0).Resize(.UsedRange.Rows.Count - 1).Rows.Delete
    .AutoFilterMode = False
End With
With Application
    .ScreenUpdating = True
    .DisplayAlerts = True
End With

End Sub
 
Upvote 0
Try this on a copy of your data
Code:
Sub Delete_Blanks()
Application.ScreenUpdating = False
      Dim LR As Long, i As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 1 Step -1
    If Range("A" & i).Value = "" Then Rows(i).Delete
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try

Sheets("Sheet2").Range("A1:A2941").SpecialCells(xlCellTypeBlanks).EntireRow.Delete

Hope that helps.
 
Upvote 0
Ughhh - talk about a shorter, quicker bit of code! I'm going to modify and steal that, thanks jonmo!
 
Upvote 0
Ughhh - talk about a shorter, quicker bit of code! I'm going to modify and steal that, thanks jonmo!

Keep in mind that specialcells(xlcelltypeblanks) will ignore formula blanks (="")
Even after that formula is copy / pastespecial / values
It is still not considered blank.


In that case, you would do

Range(....).Value = Range(....).Value

That converts them to true blanks.

THEN do the specialcells(xlcelltypeblanks).entirerow.delete
 
Upvote 0
As a modification, for something I'm thinking of for what I use it for, I could just filter and then delete visible rows.

Thanks for the heads up though
 
Upvote 0
Keep in mind that specialcells(xlcelltypeblanks) will ignore formula blanks (="")
Even after that formula is copy / pastespecial / values
It is still not considered blank.

In that case, you would do

Range(....).Value = Range(....).Value

That converts them to true blanks.

THEN do the specialcells(xlcelltypeblanks).entirerow.delete
As long as you are going to do the Range(..).Value = Range(..).Value operation in code, there is no need to perform the Copy/PasteSpecial/Values operation at all since the VB statement will handle moving the values into the cells as well as convert formula blanks to real blanks.
 
Upvote 0

Forum statistics

Threads
1,224,581
Messages
6,179,668
Members
452,936
Latest member
anamikabhargaw

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