Using FormulaArray in VBA

  • Thread starter Thread starter marcelobf
  • Start date Start date
M

marcelobf

I need to write a function the sums two arrays and return an array as a
result. This has to be made using FormulaArray. I've tried some thing
as showed below, but doesn't work.

-Function FFF(MinhaSelecao1 As Range, MinhaSelecao2 As Range) As Range

FFF.ArrayFormula = "=" & MinhaSelecao1 & "+" & MinhaSelecao2

End Function-

Does anyone can help me?
 
FormulaArray is for entering an Arrayformula in a Worksheet.

Closest you could get would be

Function FFF(MinhaSelecao1 As Range, MinhaSelecao2 As Range) As Variant
FFF = Evaluate( MinhaSelecao1.Address & "+" & MinhaSelecao2.Address)
End Function


otherwise

Function FFF(MinhaSelecao1 As Range, MinhaSelecao2 As Range) As Variant
Dim v as Variant
v1 = MinhaSelecao1.Value
v2 = MinhaSelecao2.Value

for i = to 1 to ubound(v1,1)
v1(i,1) = v1(i,1) + v2(i,1)
Next
FFF = v1
End Function

This would give you a return array of the same size as the ranges passed in.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top