# Pass more than one argument

#### tiredofit

##### Well-known Member
If I want to pass ONE argument to a SubRoutine, I can do this:

Code:
``````Dim MyArray() as Variant

MyArray() = Array("Apples", "Oranges")

Dim i As Integer

For i = LBound(MyArray(), 1) To UBound(MyArray(), 1)

Call SomeSub(Arg:=i)

Next i``````

What if SomeSub requires TWO arguments? How can I define an array, that allows more than ONE argument to be passed?

Thanks

Last edited:

### Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

#### tiredofit

##### Well-known Member
I suppose I can use a dictionary, which would be key and item but what if SomeSub requires MORE than 2 arguments?

#### RoryA

##### MrExcel MVP, Moderator
I don't really understand the question. Best guess, use a 2D array or an array of arrays, and iterate each row.

#### Norie

##### Well-known Member
Why would you need an array to pass more than one argument?

#### tiredofit

##### Well-known Member
Thanks, the 2D array method is probably the easiest, like this:

Code:
``````    Dim MyArray(1 To 2, 1 To 2) As Variant

MyArray(1, 1) = "Apple"
MyArray(1, 2) = "Orange"
MyArray(2, 1) = "Large"
MyArray(2, 2) = "Small"

Dim i As Integer

For i = 1 To 2

Call SomeSub(Arg1:=MyArray(1, i), Arg2:=MyArray(2, i))

Next I``````

Using a dictionary, this is what I've got, which also works:

Code:
``````    Dim DIC As Scripting.Dictionary
Set DIC = New Scripting.Dictionary

Dim DICElement As Variant

For Each DICElement In DIC

Call SomeSub(Arg1:=DICElement, Arg2:=DIC.Item(DICElement))

Next DICElement``````

Last edited:

Replies
3
Views
128
Replies
5
Views
118
Replies
10
Views
402
Replies
3
Views
377
Replies
10
Views
123

1,127,201
Messages
5,623,341
Members
415,968
Latest member
Chabal74

### 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.

### Which adblocker are you using?

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

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