Deleting non empty rows

J

Jan Kronsell

This code deletes the row, if the cell in column C IS empty.

Sub SletBlank()
On Error Resume Next
Columns("C:C").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub

I need it to do it, the other way around. Delete all rows, where the cell in
column C IS NOT empty. But there is no xlCellType for "Nonblank". So how do
I best do what I want.

Jan
 
N

Norman Jones

Hi Jan,

Try:

Sub Tester()
On Error Resume Next
With Range("C:C")
.SpecialCells(xlCellTypeConstants).Delete
.SpecialCells(xlCellTypeFormulas).Delete

On Error GoTo 0
End With

End Sub
 
N

Norman Jones

Hi Jan,

I forgot to extend to the entire row:

Public Sub Tester()
On Error Resume Next
With Range("C:C")
.SpecialCells(xlCellTypeConstants). _
EntireRow.Delete
.SpecialCells(xlCellTypeFormulas). _
EntireRow.Delete

On Error GoTo 0
End With

End Sub
 
J

Jan Kronsell

Hi Norman
Thank you. Your code deletes the contents of the cells, but changing it to


.SpecialCells(xlCellTypeConstants).EntireRow.Delete

and so on did the trick.

Jan
 

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