VBA: sub calling another sub multiple times and array structures

Archangelos

New Member
Joined
Aug 21, 2017
Messages
49
I have the following procedure that calls another procedure multiple times.

Code:
Sub OneSubCallingAnotherSubMultipleTimes()    
    Call uuCustomTpNames("11221", "H", "BWA", "BWA 1")
    Call uuCustomTpNames("11547", "V", "BWA", "BWA 2")
    Call uuCustomTpNames("11483", "H", "PBL", "PBL 1")
    Call uuCustomTpNames("11497", "V", "GFD", "GFD 1")
    
End Sub

No matter what the procedure "uuCustomTpNames" does, the question is: can I make an array data structure, insert a number of records and write the call command one time only?

I am thinking of something like the following.

Make ArrayDataStructure (string1, string2, string3, string4)

Insert ArrayDataStructure ("11221", "H", "BWA", "BWA 1")
Insert ArrayDataStructure("11547", "V", "BWA", "BWA 2")
Insert ArrayDataStructure("11483", "H", "PBL", "PBL 1")
Insert ArrayDataStructure("11497", "V", "GFD", "GFD 1")

For all records in ArrayDataStructure
Call uuCustomTpNames (string1, string2, string3, string4)
 
Last edited:

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi,
in the code you are calling just declare an argument with ParamArray keyword.
A ParamArray allows you to provide dynamic number of arguments to your procedure of any data type including objects.


Code:
Sub uuCustomTpNames(ParamArray Elements() As Variant)
Dim Element As Variant
For Each Element In Elements
    MsgBox Element
Next
End Sub

ParamArray must be defined as Variant datatype is always zero based and is not effected by the Option Base statement.


Code:
Sub OneSubPassingMulitpleArguments()
    Call uuCustomTpNames("11221", "H", "BWA", "BWA 1", _
                         "11547", "V", "BWA", "BWA 2", _
                         "11483", "H", "PBL", "PBL 1", _
                         "11497", "V", "GFD", "GFD 1")
End Sub

Dave
 
Upvote 0
Interesting, I will test it.

How can I add elements to a ParamArray variant?
I suppose there is a way to count the elements of a ParamArray or delete either part or all of them. I have to google it.

Thanks dmt32.
 
Upvote 0

Forum statistics

Threads
1,215,460
Messages
6,124,949
Members
449,198
Latest member
MhammadishaqKhan

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