View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Sisilla[_2_] Sisilla[_2_] is offline
external usenet poster
 
Posts: 34
Default CountIf Greater Than/Find Greater Than

Hello Don,

Thank you for your efforts to help me. I am afraid that I don't
understand how CountIf will save me iterations within the For loop.

I can count the number of cells in the range that are greater than
CompareValue, but won't I still have to compare each cell in the range,
or am i missing something?

I appreciate any further help.

Thanks,
Sisilla

Don Guillett wrote:
why not just use COUNTIF?

--
Don Guillett
SalesAid Software

"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