Run-time error: no cells found. Handling this error?

OfficeUser

Well-known Member
Joined
Feb 4, 2010
Messages
542
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I get a runtime error using this macro:
Code:
Private Sub DeleteRows()
On Error Resume Next
Columns("C:C").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
End Sub

It produces an error if there are no rows to delete. How do I prevent the error from happening? This macro is triggered from within a separate macro like this:
Code:
Run "DeleteRows"

Thanks for the help!!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
It sounds like you already have an active error, when you get to that row, otherwise the
Code:
On Error Resume Next
Would handle the error.
a) could you post the entire code for the calling macro.
b) Have a look here regarding error handling
http://excelmatters.com/2015/03/17/on-error-wtf/
 
Upvote 0
Perhaps you can answer this, but if I put 'On Error Resume Next' at the top of the procedure, why do I still get the run-time error? Not saying this is the method I should / would use, but according to the article it should not show the error...I'm confused.
 
Upvote 0
I no longer call this procedure from another macro. I now set it to run with a shortcut key, but am still getting the error.
 
Upvote 0
if I put 'On Error Resume Next' at the top of the procedure, why do I still get the run-time error?
Because of this
(From Excel Matters) While the current procedure’s error handler is active, or there is an active error condition, no further errors can be handled by that procedure.
The current procedure includes any subs that are called by, or call other subs.
Untested but try
Code:
Private Sub DeleteRows()
MsgBox Err.Number
On Error Resume Next
Columns("C:C").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
End Sub
What does the message box say?
 
Upvote 0
The box says: 0

For now, I simply insert a blank line between rows one and two and the code works, and allows everything to operate as needed. It works but now I want to understand how to handle errors. Thanks for taking time to help.
 
Upvote 0
I no longer call this procedure from another macro. I now set it to run with a shortcut key, but am still getting the error.
With this in mind, I must admit I dont understand why you still get an error, especially bearing in mind that the msgbox showed 0.
 
Upvote 0
I suspect the msgbox showed 0 because the OP used the shortcut key to run the DeleteRows sub.

The way I follow this, the error is in the sub calling the DeleteRows sub.
In post #2 Fluff asked
a) could you post the entire code for the calling macro.
but that didn't happen.
 
Upvote 0
Actually I didn't. I ran the macro by going back to the very original file where this macro is called from another routine. I figured it would be best to work from the original file.

I appreciate your follow-up, but it is a bit brash...just saying.
 
Last edited:
Upvote 0
Deleted
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,403
Messages
6,130,364
Members
449,576
Latest member
DrSKA

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