View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default CountIf Greater Than/Find Greater Than

You have answers to your main question but just to add, if your
'AtLeastCells' cells will exist in many non-contiguous areas your union loop
will become exponentially slower, eventually to a crawl. If that's a
possibility consider not making a single large multi area range object and
processing in a different way. Eg make an array of string addresses for
later use, or process intermediate range objects that exceed say 100 areas.

Regards,
Peter T


"Sisilla" wrote in message
ps.com...
Hello All,

The following code runs slowly. Is there a better way to do this,
perhaps with CountIf and Find? If there is even the smallest
improvement from comparing every cell in the SearchRange with
CompareValue, I'd love to hear the solution!

Function AtLeastCells(CompareValue As Integer, SearchRange As Range) As
Range

'Searches SearchRange for values that are greater than or equal to
CompareValue
'of Integer Data Type.
'If values are found, all matching cells are returned.
'If no value is found, an empty range is returned.

Dim rCell As Range

For Each rCell In SearchRange.Cells
If rCell.Value = CompareValue Then
Set AtLeastCells = UnionWithNothing(rCell, AtLeastCells)
End If
Next rCell

End Function

I greatly appreciate any help.

Thanks!
Sisilla