Delete row macro/VB

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

I'm looking for a macro/VB code that will evaluate a cell
and if it meets the criteria, will delete the row.

For example, if cell c5=0, then delete that row.

Can anyone help?
 
Dave here is one way,

Sub Delete_0()

' This macro deletes all rows on the active worksheet
' in column C where the valve is 0
Dim iRow As Long
Dim SpecValue As String

SpecValue = 0

If SpecValue = "" Then Exit Sub

For iRow = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
If Cells(iRow, 3) = SpecValue Then Rows(iRow).Delete
Next iRow

End Sub


--
Paul B
Always backup your data before trying something new
Please post any response to the newsgroups so others can benefit from it
Feedback on answers is always appreciated!
Using Excel 2000 & 2003
** remove news from my email address to reply by email **
 
Hi Dave,

Try:

Sub Tester()
Dim rng As Range
Set rng = Range("C5")
If rng.Value = 0 Then rng.EntireRow.Delete
End Sub
 
Here is one way

Sub RowZapper()
If Sheet1.Range("c5") = 0 Then
Sheet1.Range("c5").EntireRow.Delete
End If
End Sub

Christy;)
 
HI

Write code to iterrate through column C or per examle set C5 as activecell
then the following code will do the job


If ActiveCell.Value = "0" Then Selection.EntireRow.Delete

There are other varients of this code

Best N10
 

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

Back
Top