Passing an Array

Just like strings, integers, and other variables, arrays can be passed into other procedures. This makes for more efficient and easier-to-read code. The following sub, PassAnArray, passes the array, myArray, into the function RegionSales. The data in the array is summed for the specified region and the result returned to the sub (see Figure 17.7).

Sub PassAnArray()

Dim myArray() As Variant

Dim myRegion As String myArray = Range("mySalesData")

myRegion = InputBox("Enter Region - Central, East, West") MsgBox myRegion & " Sales are: " & Format(RegionSales(myArray, myRegion), "$#,#00.00")

End Sub

Function RegionSales(ByRef BigArray As Variant, sRegion As String) As Long Dim myCount As Integer

0 0

Post a comment