VBA Delete Range of Cells in Cols A & B if Col C is Blank

alexfooty

Board Regular
Joined
Dec 30, 2018
Messages
97
Office Version
  1. 2016
Platform
  1. Windows
In Col A I have a list of places, Col B a reference and Col C a number. There can be up to 30 rows of data.
1.png


I would like a VBA code to do the following...

Sort by Col C - smallest number first
2.png


Then delete any data in Cols A & B where Col C is blank
3.png


Bear in mind that there can be up to 30 rows of data.
I do not want to delete the entire rows as I have other data in Cols F:K that I want to keep.

Any help would be appreciated
Many thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
How about
VBA Code:
Sub alexfooty()
   With Range("A1:C" & Range("A" & Rows.Count).End(xlUp).Row)
      .Sort .Columns(3), xlAscending, , , , , , xlNo
      Intersect(.EntireColumn, .Columns(3).SpecialCells(xlBlanks).EntireRow).Delete xlShiftUp
   End With
End Sub
 
Upvote 0
A VBA demonstration for starters :​
VBA Code:
Sub Demo1()
        Dim R&
        Application.ScreenUpdating = False
    With [A1].CurrentRegion.Rows
       .Sort .Cells(3), 1, Header:=2
        R = .Cells(.Count, 3)(2).End(xlUp)(2).Row
        If R <= .Count Then .Item(R & ":" & .Count).Clear
    End With
        Application.ScreenUpdating = True
End Sub
 
Upvote 0
My code does not delete the entire row, just columns A to C ;)
 
Upvote 0
Fluff
Many thanks, that works exactly as I want it.
However,I am now having second thoughts about the layout of my spreadsheet and I'm thinking of moving this data to Cols E:G starting at row 23and also adding 2 more column C & D

4.png


Same rules would apply but delete C:F where Col G is blank.
Sorry to mess you about but I tried altering the VBA you supplied but with no success.

Thanks in advance
 
Upvote 0
How about
VBA Code:
Sub alexfooty()
   With Range("C23:G" & Range("C" & Rows.Count).End(xlUp).Row)
      .Sort .Columns(5), xlAscending, , , , , , xlNo
      Intersect(.EntireColumn, .Columns(5).SpecialCells(xlBlanks).EntireRow).Delete xlShiftUp
   End With
End Sub
 
Upvote 0
Thanks Fluff
Moved the data as described and it works perfectly. Makes my life so much easier.
Thank you so much and sorry for messing you about.
Thank also everyone who contributed
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,254
Messages
6,123,894
Members
449,132
Latest member
Rosie14

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