Find a text
You want to delete all the rows that have that string in it:
Option Explicit
Sub testme()
Dim FoundCell As Range
Dim wks As Worksheet
Set wks = Worksheets("sheet1") 'change this!
With wks.Range("E:e")
Do
Set FoundCell = .Cells.Find(what:="Samtals hreyfing:", _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If FoundCell Is Nothing Then
'no more left, get out of the loop
Exit Do
Else
FoundCell.EntireRow.Delete
End If
Loop
End With
End Sub
Using Edit|Find is usually quicker than looping through all the cells.
Geir wrote:
Hi all
I am trying to find a text and delate a Row if the text is in the row.
But I am not sure how to do it.
Can someone help me?
Option Explicit
Sub FindText()
Dim Cell As Range
For Each Cell In ActiveSheet.UsedRange
If Cell = "Samtals hreyfing:" Then
€šthe text Samtals hreyfing sin in in the column E:E
€šIf the text Samtals hreyfing: is in the row then I want to delete the Row
End If
Next Cell
End Sub
--
Dave Peterson
|