VBA to delete empty rows

KGee

Well-known Member
Joined
Nov 26, 2008
Messages
537
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I'm having a hard time finding something that will work. I have a sheet with data in columns A, B & C. Column A will always have an entry and columns B & C will either both have data or both be empty. I want to delete each row where B/C does not have data.
Code:
On Error Resume Next
Sheet1.Columns("B:B").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
I've also tried selecting the entire range of data and using this:
Code:
On Error Resume Next
Selection.EntireRow.SpecialCells(xlBlanks).EntireRow.Delete
On Error GoTo 0
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
It's likely that your blanks are not truely blank.
Were they formulas that returned "", and have since been copy / pastespecial / values ?

Try

Code:
With Sheet1.Range("B:B")
    .Value = .Value
    .SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End With
 
Upvote 0
Yes, the data is copied from one workbook to another and pasted in as values. I was thinking that might have something to do with it but couldn't figure out how to check. I just remembered about ISBLANK and confirmed that was the issue. All "blanks" were returning false unless I selected the cell and hit delete. Your suggestion did the trick.

Thanks for sorting me out.
 
Upvote 0

Forum statistics

Threads
1,215,648
Messages
6,126,007
Members
449,280
Latest member
Miahr

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