Convert "Delete Entire Rows" VBA Code from Excel 2003 to 2010

TTTon1

New Member
Joined
Dec 27, 2018
Messages
4
Hello, ive been using the following code to delete entirely empty rows (only if all the cells in 1 row are empty) within a range in excel 2003.



Code:
Sub delete1()
  Dim r As Range, rows As Long, i As Long
  Set r = ActiveSheet.Range("A1:D220")
  rows = r.rows.Count
  For i = rows To 1 Step (-1)
    If WorksheetFunction.CountA(r.rows(i)) = 0 Then r.rows(i).Delete
  Next
  End Sub

This code doesnt work in Excel 2010.

Ive read many Threads regarding deleting entire Rows but found nothing that works for what I want to do.
 
Can you elaborate on that?

I changed the range to from A:D to A:A , B:B etc and with a single column it would work.

Now ive closed the workbook and opened it again and it wont work with single columns now as well.

The only way that would happen is if there is at least one non-empty cell in each of the rows. That code will delete completely empty rows in 2010.

Youre right, this is what is happening. After manually selecting empty cells and deleting their "content" the code will work.

So the Issue is with exporting the data from a webscraping software since exporting to excel 2003 file will have blanks as blanks while exporting to xlsx will have "invisble" data in the empty cells. I have no idea what data could be in the cells.

Thank you guys for your help!
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
So the Issue is with exporting the data from a webscraping software since exporting to excel 2003 file will have blanks as blanks while exporting to xlsx will have "invisble" data in the empty cells. I have no idea what data could be in the cells.
Data pulled from the web often has special invisible characters like non-breaking spaces, that are not affected by the TRIM function.
One way to easily check if this is the case is to use the LEN function on these seemingly blank cells. If they look blank, but return a count other than 0, than that is probably what you want going on.

You can see exactly what that character is by using the CODE function, which returns the ASCII code of the character, i.e.
Code:
=CODE(LEFT(A1,1))
and then lookup the code on an ASCII table, i.e. https://www.ascii-code.com/
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,298
Members
449,077
Latest member
Rkmenon

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