troubleshooting Question

VBA Nested For loop not executing properly

Avatar of gwarcher
gwarcher asked on
Microsoft ExcelVB Script
22 Comments1 Solution981 ViewsLast Modified:
I have a simple application I wrote to remove values on one sheet that are found on another sheet.  For some reason, my For Next loop is not working and I'm not sure why as I have a similarly structured program on another subroutine.  Please let me know what I am doing wrong here.  For reference the Variable count is set above when an array is populated.  For all intensive purposes lets say it is 1000.

The problem I am having is once the inner loop is done executing the code skips the "next i" portion and moves on to the error handling below it.
Dim n As Long, i As Long, arrCount As Integer
Dim Counter As Long
Dim PctDone As Single

arrCount = 0
Counter = 1

For i = 1 To Cells(100, "A").End(xlUp).Row
    iSourceEmail = Range("A" & i).Value
    For n = 1 To count
        checkEmail = myEmailArray(n - 1)
        If checkEmail = iSourceEmail Then
            Range("A" & i).Value = ""
            arrCount = arrCount + 1
        End If
    Next n
Next i

If arrCount = 0 Then
    MsgBox ("There are no duplicates to remove")
    MsgBox ("You removed " & CStr(arrCount) & " Numbers from File")
End If
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 22 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 22 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros