Deleting rows beyond a certain point

craigg3

Board Regular
Joined
Dec 23, 2002
Messages
163
Office Version
  1. 365
Platform
  1. Windows
I have a sheet that will have different amounts of data in it. Data is from column A to K. What I need to do is find where column A has the first blank cell of data, and then delete complete rows from the first blank cell in row A.

Example row A1-500 may have data

row a501 may not have data, so I need to delete complete row from row A501 to A1001
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Hi Craig,

Please test the following code (Alt+F11 -> VBA -> insert a new module):

Code:
Sub DeleteRows()
    Dim lngFirstBlank       As Long
    Dim lngLastRow          As Long
    
    With ActiveSheet
    lngFirstBlank = .Range("A1").End(xlDown).Row + 1
    lngLastRow = .UsedRange.Rows.Count
        If CBool(lngFirstBlank * lngLastRow) Then
            .Range("A" & lngFirstBlank & ":K" & lngLastRow).[COLOR=#ff0000]Select[/COLOR]
        End If
    End With
End Sub

If you're happy with the range that macro selects for you, then change Select to Clear in order to delete the data.

Let me know if that works for you.
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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