View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
mienz mienz is offline
external usenet poster
 
Posts: 1
Default maxif function in vba


Hi
I want to write a reuseable maxif function in vba. The following cod
is working when entered directly into the cell:

=SUMPRODUCT(MAX((B1:B6=B2) * (A1:A6)))

Now I want to pack this function into vba code to make it commonl
available. I tried it with the following code but it doesn't work.
assume there is a problem with the passing of the range parameters.
also tried it with String and Variant as parameter types - withou
success. Can anybody help me?

Public Function MaxIF(criteriaRange As Range, searchValue As Variant
calcRange As Range)

AciveCell.Formula = "=SumProduct(Max((criteriaRange = searchValue
* (calcRange)))"

End Functio

--
mien
-----------------------------------------------------------------------
mienz's Profile: http://www.excelforum.com/member.php...fo&userid=1630
View this thread: http://www.excelforum.com/showthread.php?threadid=27697