Passing Arrays Between Subs

austin350s10

Active Member
Joined
Jul 30, 2010
Messages
321
I know I am doing this wrong but I what I am trying to do is pass an array from boxSelect_Change to subBox_Change. Then I want to reference that array inside subBox_Change. Is there even a way to do this?


Here is my attempt:
Code:
Private Sub boxSelect_Change()
    If boxSelect.Value <> "" Then
        lblSub.Visible = True
        boxSub.Visible = True
        Select Case boxSelect.Value
            Case "Yes"
                boxSub.List = Array("yes1", "yes2")
                pNum = Array("101", "102")
            Case "No"
                boxSub.List = Array("no1", "no2")
                pNum = Array("201", "202")
        End Select
        boxSub_Change Arr:=pNum
    Else
        lblSub.Visible = False
        boxSub.Visible = False
    End If
End Sub

Private Sub boxSub_Change(ByRef Arr() As Long)
    If boxSub.Value <> "" Then
        btnCreate.Visible = True
    End If
    
    MsgBox Arr(boxSub.ListIndex)
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Is boxSub_Change the event handler for a control? If so, you cannot change the signature.

You can declare an array at the top of the module, and read or write the array from either procedure.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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