Argument in a Sub Procedure

mdinardi

New Member
Joined
Jun 4, 2012
Messages
2
Hello there,

I searched through the questions and didn't find any question regarding arguments in sub procedures.

I am trying to write a code that will require a number for a variable (i), but if no number is typed in, it will use its default value.

Sub Ende(Optional Teste As Long = 30000000)
Teste = Application.InputBox("Defina o CEP: ", "Endereço")
MsgBox "O CEP é: " & Teste

End Sub

but nothing happens when I press F5 or F8.
When I remove the arguments, it runs normally.

What am I doing wrong here?

Best Regards,
Marcos.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
when your supply argument in sub procedure then you need to call this procedure from other sub procedure. You cant run this procedure directely.

and in your function your are passing taste with value 30000000 .. which isnot used in your sub procedure so you may remove it.
 
Upvote 0
Hello there,

I searched through the questions and didn't find any question regarding arguments in sub procedures.

I am trying to write a code that will require a number for a variable (i), but if no number is typed in, it will use its default value.

Sub Ende(Optional Teste As Long = 30000000)
Teste = Application.InputBox("Defina o CEP: ", "Endereço")
MsgBox "O CEP é: " & Teste

End Sub

but nothing happens when I press F5 or F8.
When I remove the arguments, it runs normally.

What am I doing wrong here?

Best Regards,
Marcos.

I think that you just can't drive it from inside itself. Try to add there:

Code:
Sub testende()
Ende 3000000
End Sub

and see what happens.
 
Upvote 0
and in your function your are passing taste with value 30000000 .. which isnot used in your sub procedure so you may remove it.

or make an if condition

Code:
if Teste <> 30000000 then
Teste = Application.InputBox("Defina o CEP: ", "Endereço")
endif

MsgBox "O CEP é: " & Teste
 
Upvote 0
I am ignorant of the language, but as pointed out, you cannot step thru directly. You can call w/o supplying an arg for the parameter, like:

Sub CallIt()
Call Ende
End Sub
 
Upvote 0
Hi Guys,

Thanks for your answers.
I didn't know I couldn't run a sub procedure after adding arguments to it. Using another sub procedure to run it worked just fine.

Thank you all.

Best Regards,
Marcos.
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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