call subroutine via variable with arguments

RAYLWARD102

Well-known Member
Joined
May 27, 2010
Messages
529
I have some routines that I call with a variable in example1. The need has come to pass an array to the variable called subroutine; any ideas?

Code:
Sub CommandExamples()
    Dim SomeArray As Variant
    ReDim SomeArray(0 To 0)
    
    'Example1: Example1 works; don't need any help with example 1
        Application.Run "Example1"
        
        
    'Example2: Example2 doesn't work; wondering how to run a routine that requires object sources (variant, long)
        Application.Run "Example2(" & SomeArray & ")"
End Sub
Sub Example1()
    Debug.Print "works"
End Sub
Sub Example2(ArraySource As Variant)
    Debug.Print "does not work"
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
I would think
Code:
 Application.Run "Example2" SomeArray
And then in the called macro title
Code:
Sub Example2(ByRef SomeArray As Variant)
For i = LBound(SomeArray To UBound(SomeArray)
 MsgBox SomeArray(i)
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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