View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default array output to cell range

Miek,

A function cannot change any cell except the one it is called from so you
can't write the output from your function to a cell range.

Mike

"miek" wrote:

I have three arrays
one array is a range array used as in input to my function
the second array has elements that i want to sent each element to a range
array (the third array)

workseet cell formula: =Count_duplicates(A2:A10, C2:C10)

VBA function:

Function Count_duplicates(ArrayIn, PutDupWhereArray) As Variant
Dim Num_Dups As Long
Dim Num_Blanks As Long
Dim ArrayItems_Duplicates() As Variant ' an array to put duplicates found in
'
Num_Dups = 0
ReDim ArrayItems_Duplicates(0)
'
For Each Element In ArrayIn
If Element 1 Then
ReDim Preserve ArrayItems_Duplicates(Num_Dups)
ArrayItems_Duplicates(Num_Dups) = Element
Num_Dups = Num_Dups + 1
End If
Next Element
Num_Dups = Num_Dups / 2 ' div by to to get actual duplicate pairs
For Each Element In ArrayItems_Duplicates

'Code that takes each element in array and puts it in
' PutDupWhereArray range array i.e. C2:C10

Next Element
Count_duplicates = Num_Dups
End Function

Thanks for any help