ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using FormulaArray in VBA (https://www.excelbanter.com/excel-programming/355060-using-formulaarray-vba.html)

marcelobf

Using FormulaArray in VBA
 

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?


--
marcelobf
------------------------------------------------------------------------
marcelobf's Profile: http://www.excelforum.com/member.php...o&userid=32129
View this thread: http://www.excelforum.com/showthread...hreadid=518850


Tom Ogilvy

Using FormulaArray in VBA
 
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.

--
Regards,
Tom Ogilvy


"marcelobf" wrote in
message ...

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?


--
marcelobf
------------------------------------------------------------------------
marcelobf's Profile:

http://www.excelforum.com/member.php...o&userid=32129
View this thread: http://www.excelforum.com/showthread...hreadid=518850





All times are GMT +1. The time now is 09:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com