Deleting a row based on a value in a column
Try this
Private Sub run_cleardown_Click()
Dim data As String
Dim iLastrow As Long
Dim iLastrow1 As Long
Dim iLastrow2 As Long
Dim i As Long
data = "Y"
With Sheets("Work")
iLastrow1 = .Cells(Rows.Count, "H").End(xlUp).Row
iLastrow2 = .Cells(Rows.Count, "I").End(xlUp).Row
iLastrow = iLastrow1
If iLastrow2 iLastrow Then iLastrow = iLastrow2
For i = iLastrow To 1 Step -1
If .Cells(i, "H").Value = data Or _
.Cells(i, "I").Value = data Then
.Rows(i).Delete
End If
Next i
End With
End Sub
--
HTH
RP
(remove nothere from the email address if mailing direct)
"Kai" wrote in message
. ..
Hi there!
Over the past few days I've been working on a workflow system in Excel.
One of the features that was wanted is a clear down function, which will
automatically delete all off the rows with "Y" in Sheets("Work") columns H
and I.
The only thing is I can't seem to get any form of my code to work...
The majority of snippets that require listing values in certain rows I
just
just the for each cell in rows, if cell.value2 = data then
object.additem...
etc.
Could someone help me with this code and let me know how I can make it
workable?
Private Sub run_cleardown_Click()
Dim data As String
data = "Y"
For Each cell In Sheets("Work").Range("H:H")
If cell.Value2 = data Then
EntireRow.Delete cell.Value2
Else
End If
Next
For Each cell In Sheets("Work").Range("I:I")
If cell.Value2 = data Then
EntireRow.Delete cell.Value2
Else
End If
End Sub
Thanks!
Kai
|