Forever_EX

New Member
Joined
Mar 26, 2018
Messages
22
I need code that will:
Find the first blank row in a set of data (the first blank row is ALWAYS at the bottom end of the data)
Highlight that row and every row below it
Delete

I tried this code:
Code:
'Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete

(I use Column A because that always has an entry.)

Unfortunately, it's leaving 1 blank row still at the end every time! Any help?
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
This sounds odd.
If the first blank row is always at the bottom of the data, and column A always has an entry for data in that and/or other columns, then that means that the first blank row and all rows below it down to row 1048576 are blank (or empty), so why delete rows with nothing in them? Depending on the size of your data, you should not only have "1 blank row still at the end every time", you should have about a million.
 
Upvote 0
After mulling it over for some time and checking with my coworkers I figured something out.

One of my coworkers uses "Clear Contents" instead of "Delete".

Then she fills in some data.

Later, we have a form someone else uses which steps through the rows of data and displays them (through use of a spin button.)

Because of the use of "Clear Contents" instead of "Delete" this somehow is why we end up with blank rows of data at the end that the form tries to read and display. (If the rows are really blank and never had anything entered into them, they won't get displayed, no problem.)

Although the rows appear empty, the form still steps through them as though they have data. Maybe this explains why I want to "Delete" rows with nothing in them!

I'm new to VBA and thinking now of a way to improve my code.
 
Last edited:
Upvote 0
It is probably because the usedrange retains a memory, does the below sort it?
Test on a copy of the sheet.


Code:
Sub LoseThatWeight()

    Dim xLastRow As Long
    Application.ScreenUpdating = False

        With ActiveSheet
            LastRow = .Cells.Find(What:="*", After:=.Range("A1"), LookIn:=xlValues, _
                                  LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            .Range(.Cells(LastRow + 1, 1), .Cells(Rows.Count, Columns.Count)).Delete
        End With
  
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,211,697
Messages
6,103,359
Members
447,861
Latest member
LllopezXC

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