Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I delete empty cells in Excel using VBA after a Copy/Paste?

I want to delete all rows that contain empty cells in a particular range (columns A and B).
I tried multiple options, which I found here on SO.

Columns("A:B").SpecialCells(xlCellTypeBlanks).EntireRow.Delete

and I have also tried:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Lastrow = Range("A:Z").Find("*", , , , xlByRows, xlPrevious).Row

For i = Lastrow To 1 Step -1
    If Application.CountA(Range(Cells(i, 1), Cells(i, 2))) = 0 Then Rows(i).Delete
Next i

However: both options don’t find my empty cells. I think the reason must be that they have been pasted (PasteSpecial-Values only) into my Excel sheet. They contain no values, but is it possible there’s still some metadata that prevents them from being "found" by the algorithm? Both macros don’t find any empty cells and basically do nothing.
Thank you for your help.

>Solution :

Try this

For i = Lastrow To 1 Step -1 
    If trim(cells(i, 1))= ""  or trim(cells(i, 2))= "" then cells(i, 1).entirerow.Delete
Next i
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading