Trouble understanding how to apply "on error resume next"

BustedAvi

New Member
Joined
Jun 24, 2010
Messages
27
Hello,

I have the following code

Code:
'remove rows of blank data (if data is not entered)
Sub deleterows()
    Sheets("Page 1").Select
    Columns(4).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub
This is designed to remove rows when the cell in column 4 is blank. However, if all columns are full, I get "subscript out of range".

I've done some researching and I've being trying to understand how to have the code handle errors. What I need is for it to simply ignore deleting rows altogether if column 4 does not contain cells of blank data.

From my understanding,

Code:
'remove rows of blank data (if data is not entered)
Sub deleterows()
    Sheets("Page 1").Select
    Columns(4).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error Resume Next
End Sub
would require the next line of code to correct for the error - but how do i do this?

I appreciate your help.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
If this macro is REALLY this short, then you only need the two commands, FIRST comes the instruction telling Excel what to do if an error occurs, THEN the code that "might" error. You also do not need to 'activate' a sheet to send a command to it.

Code:
Sub DeleteRows()

    On Error Resume Next
    Sheets("Page 1").Columns(4).SpecialCells(xlCellTypeBlanks).EntireRow.Delete

End Sub
 
Upvote 0
It's not really that short of a macro but your info solved my problem.

Wow. Can't believe how simple that was. I feel stupid.
 
Upvote 0

Forum statistics

Threads
1,224,526
Messages
6,179,322
Members
452,906
Latest member
Belthazar

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