runtime 1004 error on deleting rows with blank cells

J

Janis

Hi
I get a runtime 1004 application or object defined error when I run this. I
want to delete the rows with blanks in column "M".

TIA
-------------code---------

Public Sub deleteRows()



Dim rngToDelete As Range

With ActiveSheet
On Error Resume Next
Set rngToDelete = .Range(.Range("M1"), .Cells(Rows.Count,
"M").End(xlUp)).SpecialCells(xlCellTypeBlanks)

On Error GoTo 0
End With

If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete


End Sub
 
M

Mike H

Janis,

I gave you the code in your previous post,

Sub deleteit()
Set myRange = Range("M1", Range("M65536").End(xlUp))
myRange.SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub

Right click the sheet tab, view code and paste it in.

Mike
 
J

Janis

Hi Mike
I will use yours, thanks, I used the other one because I thought it might
need the error checking.
jr.
 
J

Janis

Maybe it doesn't need error checking since it only removes the blank cells
and if there is none it won't delete anything.
thanks,
 
M

Mike H

My thoughts exactly

Janis said:
Maybe it doesn't need error checking since it only removes the blank cells
and if there is none it won't delete anything.
thanks,
 
J

Janis

Mike:

I got an erorr 400 while running this code:


Option Explicit

Public Sub deleteRows()

Dim rngToDelete As Range


Set rngToDelete = Range("M1", Range("M65536").End(xlUp))
rngToDelete.SpecialCells(xlCellTypeBlanks).EntireRow.Delete


End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top