View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
joel joel is offline
external usenet poster
 
Posts: 9,101
Default delete code keeps going and coing

You are deleting every blnak row in the workbook up to row 65,536. Try this
change


from

With wks
Set myRng = .Range("a6:a" & .Rows.Count)
End With

to

With wks
LastRow = .Range("A" & rows.count).end(xlup).row
Set myRng = .Range("a6:a" & LastRow)
End With


"Wanna Learn" wrote:

Hello I copied this code in the from one of the Answers in the Comunity
to "This workbook" I adjusted to read column J but when I run the code
it keeps going and going . it does not stop. I need this to look in cloumn
J3 to J7000 thanks
Option Explicit
Sub testme02()

Dim myRng As Range
Dim FoundCell As Range
Dim wks As Worksheet
Dim myStrings As Variant
Dim iCtr As Long

myStrings = Array("ISA") 'add more strings if you need

Set wks = ActiveSheet

With wks
Set myRng = .Range("a6:a" & .Rows.Count)
End With

For iCtr = LBound(myStrings) To UBound(myStrings)
Do
With myRng
Set FoundCell = .Cells.Find(what:=myStrings(iCtr), _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)

If FoundCell Is Nothing Then
Exit Do
Else
FoundCell.EntireRow.Delete
End If
End With
Loop
Next iCtr
End Sub