More than one Variable between a Function and a Sub

Philosophaie

Active Member
Joined
Mar 5, 2010
Messages
256
I am trying to pass more than one variable of data thru to and from a Function. There is no dimension statement in the Subroutine because I am not sure how to do "n" and "f1". I just keep getting "Type Mismatch" Errors.

Code:
Sub FromFunction()
        a = Cells(2, 2).Value
        b = Cells(2, 3).Value
        n = Array(a, b)
        f1 = function1(n)
        Cells(8, 2) = f1.c
        Cells(8, 3) = f1.d
        Cells(8, 4) = f1.e
    End With
End Sub
Function function1(ByRef n)
    a1 = n(0)
    b1 = n(1)
    c = a1 + 1
    d = b1 * 2
    e = 5 * b1 + 2 * a1
    f = Array(c, d, e)
    function1 = f
End Function
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
I'm sure there is more to this than you are posting, which is fine, as this looks like part of a larger project, but still, it looks a bit odd, as if you are going through more trouble than you need to. What is it you are ultimately wanting to achieve that has given rise to wanting to do this? I get the feeling there is an easier path to what you want to do, if you can provide a sense of the bigger picture so someone can assist.
 
Upvote 0
Yes it is a bigger program but I just need a refresh on how to use an Array in a function going to and from a subroutine. In Visual Basic you would use a Class structure but I do not recall it now.

I just need to know how to dimension the Subroutine so you get the return og the subroutine and the array that follows:

f1 = function1(n)
Cells(8, 2) = f1(0)
Cells(8, 3) = f1(1)
Cells(8, 4) = f1(2)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,903
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top