parameter

X

x taol

I have a Userform.
the userform have 9 button.
cmdBtn1, cmdBtn2, .... cmdBtn9
that buttons have a procedure respectively.
I want to run the button procedure using loop.

for example,

for i=1 to 9
application.run "cmdBtn" & i
next

but debug....
How can I.....
 
J

JLGWhiz

If you are going to run nine procedures consecutively, then why not take them
out of the controls, rename them and put them in a module. Then you can
create a master procedure that calls the nine, as in the example below:

Sub master()
macro1
macro2
...
macro9
End Sub
Or, if you need to use a command button, then call them all from one
button's click event in a similar manner as the example above.
 
O

OssieMac

What you can do is shift the code for each button to a module and then call
the sub in the module when the individual button is clicked.

Examples:-
Private Sub cmdBtn1_Click()
Call modCmdBtn1
End Sub

Private Sub cmdBtn2_Click()
Call modCmdBtn2
End Sub

In the module you then set your subs up as per this example:-

Sub modCmdBtn1()
MsgBox "This is modCmdBtn1()" 'Used this for testing
End Sub

Sub modCmdBtn2()
MsgBox "This is modCmdBtn2()"
End Sub

The following if attached to a button will call each of the subs in the
module using the For/Next routine.

Private Sub RunCode_Click()

For i = 1 To 9
strSubName = "modCmdBtn" & i
Application.Run (strSubName)
Next i

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top