For ... next loop problem

I wrote the code as the following:intPrevNum = Ubound(PrevProductContact)

intCurNum = Ubound(CurProductContact)

If intPrevNum >= intCurNum Then

	For i = 0 To intCurNum

		For n = 0 To intPrevNum

			If CurProductContact(i) = PrevProductContact(n) Then

				PrevProductContact(n) = ""

				CurProductContact(i) = ""

				i = i + 1

			End If

		Next

	Next

Else  ' intPrevNum < intCurNum

	Msgbox + intPrevNum

	For i = 0 To intPrevNum

		Msgbox + intCurNum

		For n = 0 To intCurNum

			If PrevProductContact(i) = CurProductContact(n) Then

				Msgbox + prevProductContact (i)

				Msgbox + curProductContact (n)

				PrevProductContact(i) = ""

				CurProductContact(n) = ""

				i = i + 1

			End If

		Next

	Next

End If

but one problem is that if intPrevNum = 1 and intCurNum = 2, then it will show an error msg saying out of range… how to fix the problem?

Subject: Your problem is the i = i + 1 line in the inner loop.

I assume that you are trying to get a list of contacts added and contacts removed from the lists. Why not use Replace?cAdded = FullTrim(Replace(CurProductContact, PrevProductContact, “”))

cRemoved = FullTrim(Replace(PrevProductContact, CurProductContact, “”))

Subject: For … next loop problem

Looks like you need to change the line “i=i+1” to “exit for”

dzp

Subject: RE: For … next loop problem

exit for is working for the code… thanks so much