Delete row based on contents of cell

G

Guest

The following code does a great job of finding whole blank rows and deleting
them:

Range("B1", Range("B65536").End(xlUp)).SpecialCells _
(xlCellTypeBlanks).EntireRow.Delete

However, could someone please tell me how to modify this for two other
purposes:

1) Delete the whole row if any cell in column A: is has the contents of "SSN"

2) Delete the whole row if any cell in column C: is blank (null?)

Thank you in advance.
 
D

Don Guillett

One way is to use data>filter>autofilter and record while doing it to
learn. Post back after you have tried this with addl questions.
 
G

Guest

Thank you Don,
I do know how to use the data>filter>autofilter then custom, not equal to
"SSN" to filter out the row in the view, however I really would like to
programmatically (macro) delete the row. If I have filters on I am also
limited (can't insert columns, etc.). Should I have posted this to the
Programming/Coding section instead of here?

Thank you again
 
G

Guest

Thank you very much Ron. The link you supplied showed me the code I needed.
God bless you for being willing to share your expertise. Thank you, Andy
 
G

Guest

Can this be used to delete cells only if the have returned blank as a False
response to a function?
 
R

Ron de Bruin

Hi Olivia

No, you must test for "" then in a loop
Example that test A1:A100

Sub Example2()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = 100
For Lrow = EndRow To StartRow Step -1
If IsError(.Cells(Lrow, "A").Value) Then
'Do nothing, This avoid a error if there is a error in the cell

ElseIf .Cells(Lrow, "A").Value = "" Then .Rows(Lrow).Delete

End If
Next
End With
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
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