Looping through Sheet
Hi Scott,
With the appropriate worksheet and the requisite cells pre-selected, your
code worked for me.
Avoiding selections, try:
Sub DeleteRows()
Dim theRange As Range, nCells As Integer, I As Integer
Dim lastRow As Long
With Sheets("Sheet1") '<<===== CHANGE TO SUIT
lastRow = .Cells(Rows.Count, "B").End(xlUp).Row
Set theRange = .Range("B2:B" & lastRow)
End With
nCells = theRange.Cells.Count
For I = nCells To 1 Step -1
If theRange.Cells(I).Value = "myword" Then
theRange.Cells(I).EntireRow.Delete
End If
Next
End Sub
---
Regards,
Norman
"scott" wrote in message
...
I'm trying to start at B1, then go down until I find a cell containing
"myword" and delete the row with "myword". I'm failing bad and need help.
I've looked at many examples like below, but can't get them to run.
Sub DeleteRows()
Dim theRange As Range, nCells As Integer, I As Integer
Set theRange = Selection
nCells = theRange.Cells.Count
For I = nCells To 1 Step -1
If theRange.Cells(I).Value = "myword" Then
theRange.Cells(I).EntireRow.Delete
End If
Next
End Sub
|