Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 1.58 KB

understanding-parameter-arrays.md

File metadata and controls

45 lines (32 loc) · 1.58 KB
title keywords f1_keywords ms.assetid ms.date ms.localizationpriority
Understanding parameter arrays (VBA)
vbcn6.chm1076759
vbcn6.chm1076759
42438a68-37a8-85d0-6404-1df4266fe33d
12/26/2018
medium

Understanding parameter arrays

A parameter array can be used to pass an array of arguments to a procedure. You don't have to know the number of elements in the array when you define the procedure.

You use the ParamArray keyword to denote a parameter array. The array must be declared as an array of type Variant, and it must be the last argument in the procedure definition.

The following example shows how you might define a procedure with a parameter array.

Sub AnyNumberArgs(strName As String, ParamArray intScores() As Variant) 
 Dim intI As Integer 
 
 Debug.Print strName; " Scores" 
 ' Use UBound function to determine upper limit of array. 
 For intI = 0 To UBound(intScores()) 
 Debug.Print " "; intScores(intI) 
 Next intI 
End Sub

The following examples show how you can call this procedure.

AnyNumberArgs "Jamie", 10, 26, 32, 15, 22, 24, 16 
 
AnyNumberArgs "Kelly", "High", "Low", "Average", "High" 

See also

[!includeSupport and feedback]