S
Scott Wagner
Below is a piece of code I use to delete rows that contain a specific keyword
in a designated column. Right now I specify the range m2:m1500, but rarely
have that many lines in the raw data. I chose the number 1500 to be sure the
code runs on all lines. Right now this is the largest time contributor to
the macro I run on the data, of which this is a small part.
Is there an approach I can follow other than the one shown below that
addresses the speed, and would also not require me to specify the range... so
it acts only the actual number of row of data in the worksheet?
Thanks,
Scott
'----------------------------------------------------
'Delete extra lines
'----------------------------------------------------
myWords = Array("2")
Set wks = ActiveSheet
With wks
With .Range("m2:m1500")
For iCtr = LBound(myWords) To UBound(myWords)
Do
Set FoundCell = .Cells.Find(What:=myWords(iCtr), _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
If FoundCell Is Nothing Then
Exit Do
Else
FoundCell.EntireRow.Delete
End If
Loop
Next iCtr
End With
End With
in a designated column. Right now I specify the range m2:m1500, but rarely
have that many lines in the raw data. I chose the number 1500 to be sure the
code runs on all lines. Right now this is the largest time contributor to
the macro I run on the data, of which this is a small part.
Is there an approach I can follow other than the one shown below that
addresses the speed, and would also not require me to specify the range... so
it acts only the actual number of row of data in the worksheet?
Thanks,
Scott
'----------------------------------------------------
'Delete extra lines
'----------------------------------------------------
myWords = Array("2")
Set wks = ActiveSheet
With wks
With .Range("m2:m1500")
For iCtr = LBound(myWords) To UBound(myWords)
Do
Set FoundCell = .Cells.Find(What:=myWords(iCtr), _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
If FoundCell Is Nothing Then
Exit Do
Else
FoundCell.EntireRow.Delete
End If
Loop
Next iCtr
End With
End With