Delete rows from botton up within range if both column C and D cells are blank

John_356

New Member
Joined
Jan 17, 2021
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Good day,

Provided LRR has been successfully defined as last used row,

I've been trying to find a way to delete all rows within my dynamic range (Range ("C2:D" & LRR)) when both cells from same row on columns C and D are blank.

I'm looking for a short and elegant code here :)

Many thanks in advance,

John
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
57,019
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
Sub John()
   On Error Resume Next
   Intersect(Range("C:C").SpecialCells(xlBlanks).EntireRow, Range("D:D").SpecialCells(xlBlanks).EntireRow).Delete
   On Error GoTo 0
End Sub
 

John_356

New Member
Joined
Jan 17, 2021
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Hi @Fluff ,

Thank you for your input.
I'm afraid that had no effect on my rows 😟
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
57,019
Office Version
  1. 365
Platform
  1. Windows
That would suggest that either the cells are not truly blank, or you have no rows where both C & D are blank.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
57,044
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Thank you for your input.
I'm afraid that had no effect on my rows
His solution worked fine for me.

I am guessing that your columns C and D may not really be blank.
Are you sure there are spaces or other non-visible characters in them?

Or, are there formulas in those cells which are returning the blanks?
Is so, what exactly are those formulas?
 

John_356

New Member
Joined
Jan 17, 2021
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Hi @Joe4 , @Fluff ,
Indeed you are both right, thank you for finding the problem, cells are indeed not blank!
Yet they seem blank, no spaces nor formulas... When I test them on the side with an ISBLANK formula the result is indeed FALSE, and if I hit delete on the cell the result changes to TRUE.

Now given cells are visually blank but not really blank, how can I get rid of those poser cells?
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
57,044
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Let's find out what is really in one of those cells.
Identify a "blank" cell. Let's say it is cell C6.
Then enter this formula in any blank cell and tell us what it returns:
Excel Formula:
=CODE(C6)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
57,019
Office Version
  1. 365
Platform
  1. Windows
Try
VBA Code:
Sub John()
   With Intersect(ActiveSheet.UsedRange, Range("C:D"))
      .Value = .Value
   End With
   On Error Resume Next
   Intersect(Range("C:C").SpecialCells(xlBlanks).EntireRow, Range("D:D").SpecialCells(xlBlanks).EntireRow).Delete
   On Error GoTo 0
End Sub
 
Solution

John_356

New Member
Joined
Jan 17, 2021
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Okay, great!

When I use the =CODE(C6) formula I get #VALUE!

Now if I write text say "ASD" in C6 just to see what happens and I get a value "65" in return (!)
If I repeat the same with lower case "asd" I get "97" - weird!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
57,019
Office Version
  1. 365
Platform
  1. Windows
Forgot to ask if you have any formulae in C or D.
If you do, don't use the code I posted.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,407
Messages
5,641,968
Members
417,249
Latest member
serrulate

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