What does this Code Actually do Please
"Paul Black" wrote in message
oups.com...
Hi Everyone,
I found this Code that Seems to Test for Duplicates :-
Could Somebody Kindly Explain what the ...
For I = 1 To 5
nNum(i) = ActiveCell.Offset(0, i - 1).Value
Do Until nNum(i) < 10
nNum(i) = nNum(i) - 10
Loop
Next i
Bit of Code is Actually doing, and the ...
It is looping through the activecell and 4 to the right and loading the
values in an array, reducing it to a maxd of 9 by decrements of 10
For i = 1 To 4
For j = I + 1 To 5
If nNum(i) = nNum(j) Then
nDupl = nDupl + 1
End If
Next j
Next i
Bit of Code is Actually doing, and ...
This is looping through that array counting how many items are repeated.
Select Case nDupl
Case 1
nDupl = 2
Case 2
nDupl = 4
Case 4
nDupl = 5
Case 6
nDupl = 4
Case 10
nDupl = 5
End Select
the Bit of Code is Actually doing Please.
Odd? It is changing the number of duplicates found 1-2, 2-4, 4-5, etc.
This is presumably because it can double-count the items, for instance a
series of 1,2,1,1, the first 1 will find 2 duplicates, the second one will
find another one, double counting. However, there must a simpler method, and
it is flawed as the example I gave shows 3 duplicates when there are only 2
in reality, the case code doesn't cater for that.
I also cannot understand why 101 is considered a duplicate of 1.
|