Thread
:
Never-ending For Next Loop
View Single Post
#
1
Posted to microsoft.public.excel.programming
Don Guillett
external usenet poster
Posts: 10,124
Never-ending For Next Loop
something like this to delete the rows
for i=cells(rows.count,"a").end(xlup).row to 2 step -1
if len(cells(i,"a"))<3 then rows(i).delete
next i
--
Don Guillett
SalesAid Software
"Helen" wrote in message
...
I want to delete any lines in a spreadsheet where the first column doesn't
conform to a three character code. This includes blank cells, but also
strings with more or less characters. The code should start from Row 4.
I came up with the following:
Sheets("Purchase Report").Select
Range("A1").Select
myRows = Selection.CurrentRegion.Rows.Count
Cells(4, 1).Select
For x = 4 To myRows
Cells(x, 1).Select
Company = Sheets("Purchase Report").Cells(x, 1)
If Len(Company) = 3 Then
GoTo PlantNumberOK
Else
Rows(x).Delete
x = x - 1
myRows = myRows - 1
PlantNumberOK:
End If
Next x
Somehow when I run this X can become a higher number than myRows, and when
it runs out of data it starts to delete the blank cells beneath the myRows
set. What have I done wrong?
Reply With Quote
Don Guillett
View Public Profile
Find all posts by Don Guillett