View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
shockley shockley is offline
external usenet poster
 
Posts: 135
Default for loop exiting out early

It runs the If statement for me. Sounds like "intCounter" is not getting
1 for you.

HTH, Shockley



"jimmy" wrote in message
...
I have the following piece of code that contains 1 for
loop with two imbedded for loops in it. The problem i am
having is that the deepest for loop (ws2) when finishing
breaks out of both outer for loops (r, ws) and exits to
the end. I am not understanding why. the program doesnt
even run through to the if statement (intCounter), just
breaks when for loop (ws2) completes. Any suggestions....

For Each ws In ActiveWorkbook.Sheets
ws.Activate
If Selection.Rows.Count 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If


For r = Rng.Rows.Count To 1 Step -1
V = Rng.Cells(r, 1).Value
intCounter = 0

For Each ws2 In ActiveWorkbook.Sheets
intCounter = intCounter +
Application.WorksheetFunction.CountIf(ws2.Columns( 1), V)
Next ws2

If intCounter 1 Then
Rng.Rows(r).EntireRow.Delete
N = N + 1
End If

Next r


Next ws