Link to home
Start Free TrialLog in
Avatar of A G
A GFlag for United States of America

asked on

Returning multiple values on vba with a function

I have a function, which is a web query. It gets the table from internet and pastes it on Cell E111.
The information I need is on Cells F111 and F114.

so after the webquery I tried something like this and didnt work
myfunction = b(Sheets("LiveSheet").Range("F111").Value, Sheets("LiveSheet").Range("F114").Value)

I need to put the values, i return from the function into two different cells on excel.

Also the function is used in a vba subroutine.
Avatar of Carlos Ramirez
Carlos Ramirez
Flag of United States of America image

Break your function into two explicit parts and try something like:

Range("A1").Value = myfunction1()
Range("B1").Value = myfunction2()
Return an array from your function.

I *think* something like this might work in VBA...
Function DoIt(parm As Long) As Variant
    Doit = Array(parm,9,15)
End Function

Dim x as Variant

x = Doit(4)

Msgbox x(0)
Msgbox x(1)
Msgbox x(2)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of AgeOfEmpires
AgeOfEmpires
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial