Discussion:
how can I delete rows based on column value
(too old to reply)
mike
17 years ago
Permalink
How can I delete certain rows of my worksheet that has a specific value in a
specific column. For example, delete all rows that have a value of '0' in
column 'C'??

Mike
Bob Phillips
17 years ago
Permalink
apply an autofilter to column C, filter on 0, and then just delete the
visible rows.
--
__________________________________
HTH

Bob
Post by mike
How can I delete certain rows of my worksheet that has a specific value in a
specific column. For example, delete all rows that have a value of '0' in
column 'C'??
Mike
StumpedAgain
17 years ago
Permalink
The following works for one "0". You can build a loop around this and use
FindNext() to locate others.

Option Explicit
Sub find()

Dim c As Range
Set c = Range("C:C").find(What:="0")
Rows(c.Row).Delete

End Sub
Post by mike
How can I delete certain rows of my worksheet that has a specific value in a
specific column. For example, delete all rows that have a value of '0' in
column 'C'??
Mike
StumpedAgain
17 years ago
Permalink
PS. I like bob's idea better (just refreshed the page) :)
Post by mike
How can I delete certain rows of my worksheet that has a specific value in a
specific column. For example, delete all rows that have a value of '0' in
column 'C'??
Mike
mike
17 years ago
Permalink
That still deleted everything.
Post by StumpedAgain
PS. I like bob's idea better (just refreshed the page) :)
Post by mike
How can I delete certain rows of my worksheet that has a specific value in a
specific column. For example, delete all rows that have a value of '0' in
column 'C'??
Mike
mike
17 years ago
Permalink
I gues I could just sort and delete, that's even simpler. I don't really need
to preserve thorder.
Post by StumpedAgain
PS. I like bob's idea better (just refreshed the page) :)
Post by mike
How can I delete certain rows of my worksheet that has a specific value in a
specific column. For example, delete all rows that have a value of '0' in
column 'C'??
Mike
RyanH
17 years ago
Permalink
This shoudl do the trick.

Sub DeleteRows()

Dim i As Long
Dim LastRow As Long

LastRow = Sheets("Sheet1").Cells(Rows.Count, "C").End(xlUp).Row

For i = LastRow To 1 Step -1
If Range("C" & i) = 0 Then
Range("C" & i).EntireRow.Delete
End If
Next i

End Sub
--
Cheers,
Ryan
Post by mike
How can I delete certain rows of my worksheet that has a specific value in a
specific column. For example, delete all rows that have a value of '0' in
column 'C'??
Mike
Gord Dibben
17 years ago
Permalink
Sub DeleteRows_With_Zero()
FindString = "0"
Set b = Range("C:C").Find(what:=FindString, lookat:=xlWhole)
While Not (b Is Nothing)
b.entirerow.Delete
Set b = Range("C:C").Find(what:=FindString, lookat:=xlWhole)
Wend
End Sub


Gord Dibben MS Excel MVP
Post by mike
How can I delete certain rows of my worksheet that has a specific value in a
specific column. For example, delete all rows that have a value of '0' in
column 'C'??
Mike
Continue reading on narkive:
Loading...