Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Follow up For loop exiting out early

I have this piece of code which jouni helped out with.
the code doesnt really do anything because the imbedded
for loop cuts out of the outer for loop and exiting the
macro. it exits out before executing the most important
command. i dont know why....

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


the inner for loop is the one that cuts out, it goes
through properly like its supposed to but then it skips
over the if statement and goes completely out of the outer
for outside the Next ws command. Any ideas why this is
happening?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Follow up For loop exiting out early

Jimmy,

you set intCounter is set to 0, then add 1 to it, so it
is equal to 1. Then the inner loop checks to see if it is
greater than 1. Well... it is not, so it moves on.

I think you could just change the line:
If intCounter 1 Then
to:
If intCounter 0 Then

but maybe I missed something.

Claire
BestMeasure @ hotmail . com

-----Original Message-----
I have this piece of code which jouni helped out with.
the code doesnt really do anything because the imbedded
for loop cuts out of the outer for loop and exiting the
macro. it exits out before executing the most important
command. i dont know why....

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


the inner for loop is the one that cuts out, it goes
through properly like its supposed to but then it skips
over the if statement and goes completely out of the

outer
for outside the Next ws command. Any ideas why this is
happening?
.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
formula help - avtive early j5b9721 Excel Worksheet Functions 0 August 28th 09 04:42 AM
15 minutes early Glenn_H Excel Discussion (Misc queries) 4 January 31st 08 06:44 PM
Early Login, Last Logout junoon Excel Worksheet Functions 3 May 9th 07 04:04 PM
How do I convert wb1 (Early Quattro Pro) to xls (Excel 2003) Ken Lewis Excel Discussion (Misc queries) 0 July 4th 06 04:25 PM
Loop ends early BrianB Excel Programming 0 August 15th 03 12:13 PM


All times are GMT +1. The time now is 10:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"