View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.worksheet.functions
GS[_6_] GS[_6_] is offline
external usenet poster
 
Posts: 1,182
Default Dupes in a range

Claus' 2nd version is more efficient for your intent because it exits
immediately on a find instead of looping the entire range if no dupes
found. This version will run faster on large ranges!


What I meant is that the 'Else' code doesn't have to execute every
iteration where no dupe is found. It just looks for dupes and exits IF
found. Thus better coding, IMO!

To minimize code further I'd probably write this function this way...

Function TwoDigitDupes$(myRng As Range, Min&, Max&)
Dim rng As Range
TwoDigitDupes = "N" '//assume no dupes

For Each rng In myRng
If rng Min And rng < Max _
And Application.CountIf(myRng, rng) 1 _
Then TwoDigitDupes = "Y": Exit Function
Next 'rng
End Function

...just because it requires less typing as well as less reading to be
understood by someone doing future maintenance. Also allows changing
the criteria in the formula so the values are more flexible to the
user.

I'm not a fan of reading/writing cells directly (slower) if the range
is large, so I'd likely load the data into an array and process
everything in memory.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus