find row and delete

  • Thread starter Thread starter Native
  • Start date Start date
N

Native

I need some help getting Excel to find a row based on a criteria in the
cell and then deleting the row.

For example, how could I get Excel to find any cell in column A that
has "alpha" in the cell to delete the entire row?

I have this from a previous post, which gets me almost there, but I
need it to ignore the first 10 rows (ie-any "alpha" in the first ten
rows stay).

I tried to modify the range to Range("a10:a10000") but it didn't work.

Public Sub test()
line2:
Range("a10").Activate
On Error GoTo line1
Cells.Find(what:="alpha").Activate
ActiveCell.EntireRow.Delete
GoTo line2
line1:

End Sub

Thanks!
 
Sub DelRows1()

Dim RowNdx As Long
Dim LastRow As Long

LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
For RowNdx = LastRow To 11 Step -1
If InStr(UCase(Cells(RowNdx, "A").Value), "alpha") Then
Rows(RowNdx).Delete
End If
Next RowNdx

End Sub

---------------------------------------------------

Sub DelRows2()

Dim RowNdx As Long
Dim LastRow As Long
Dim Ans As String

Ans = InputBox("What string do you want rows to be deleted if it contains
it?")

LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
For RowNdx = LastRow To 11 Step -1
If StrComp(Cells(RowNdx, "A"), Ans, vbBinaryCompare) = 0 Then
Cells(RowNdx, "A").EntireRow.Delete
End If
Next RowNdx

End Sub


---------------------------------------------------

Sub DelRows3()
Dim R As Long
Dim Ans As String
Dim c As Range
Dim lrow As Long

Ans = InputBox("What string do you want rows to be deleted if they contain
it?")
Application.ScreenUpdating = False

lrow = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count
For R = lrow To 11 Step -1
With Cells(R, 1)
Set c = .find(Ans, LookIn:=xlValues)
If Not c Is Nothing Then
.EntireRow.Delete
End If
End With
Next R
Application.ScreenUpdating = True

End Sub
 
Sub DeleteRow()
'Adapted from Microsoft code found at
'msdn.microsoft.com
Dim sFind As String
Dim Rng As Range
Dim sFindRow As Long
sFind = "alpha"
Set Rng = Range("A:A").Find(What:=sFind, lookat:=xlWhole)
While Not Rng Is Nothing
sFindRow = Rng.Row
Rng.EntireRow.Delete
Set Rng = Range("A" & sFindRow - 1 & ":A" & _
Rows.Count) _
.Find(What:=sFind, lookat:=xlWhole)
Wend
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

Back
Top