Condense a range to exclude blank rows

Bluzdude

New Member
Joined
Jan 21, 2009
Messages
23
I have a large range of cells. Some of the rows within this range contain all blank cells. I need a macro that will identify the blank rows and move the next row that contains values up to the last row that contained values, thus, condensing or compressing the range to include only rows that contain values. Each row will have a column that, when blank, indicates that the rest of the cells on that row are also blank.

I don't want to delete entire rows from the worksheet because that would remove data in other locations on the rows.

I assume the macro would have to do something like stepping through each row in the range and then do a "select" and "move" for the rows below the last row containing values and continue to the bottom of the range.

Is this possible?
 
Run this version. It loops up from the bottom of the table.
Code:
Sub NoBlanks_2()
    Dim c As Range
    Dim Rw As Long, RwLast As Long
    
    RwLast = Range("A65536").End(xlUp).Row
    
    For Each c In Range("A:B").SpecialCells(xlCellTypeConstants)
        If c.Value = "" Then c.ClearContents
    Next c
    For Rw = RwLast To 2 Step -1
        If IsEmpty(Cells(Rw, 1)) Then
            Cells(Rw, 1).Resize(1, 2).Delete shift:=xlShiftUp
        End If
    Next Rw
End Sub
Denis

This code works like a charm!!!! Great work, Denis!!
Thanks for being so patient with me. This will be a terrific timesaver!!
 
Upvote 0

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,215,219
Messages
6,123,687
Members
449,117
Latest member
Aaagu

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