VBA Sort Blanks

db2021

New Member
Joined
Jul 7, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I am trying to sort a sheet by blanks in 2 columns. For example, any row that has blanks in both key columns will be deleted. However, if either or both columns have information, it should be left alone. I'm struggling to get this to work with both columns rather than just one.

1625671615989.png
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
59,397
Office Version
  1. 365
Platform
  1. Windows
Welcome to the Board!

Here is one way:
VBA Code:
Sub MyDeleteRows()

    Dim lr As Long
    Dim r As Long
    
    Application.ScreenUpdating = False
    
'   Find last row in column A with data
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Loop through all rows backwards up to row 3
    For r = lr To 3 Step -1
'       Check for blanks in columns B and C and delete rows
        If Cells(r, "B") = "" And Cells(r, "C") = "" Then Rows(r).Delete
    Next r
    
    Application.ScreenUpdating = True
    
End Sub
 

Forum statistics

Threads
1,143,677
Messages
5,720,246
Members
422,272
Latest member
ginkgoVil

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
Top