6

In a new excel spreadsheet, I have inserted a new module and entered a public sub. When trying to test, the sub does not appear in the macro list unless I remove the parameter.

This behaviour is bizarre and I cannot find any reference to it as an issue, everything I have read declares that subroutines (or functions, tried that too) can have parameters.

Public Sub RetrieveSIR()  <-- Can be found
Public Sub RetrieveSIR( SIRNumber as Integer)  <-- Cannot be found

It is driving me around the bend trying to work this out. If anyone can help, it would be much appreciated.

1 Answer 1

11

Subs with parameters won't show up in the macro list for the same reason you can't simply run a sub with parameters from the vba editor screen. They can only be called via code so the parameter required can be input.

Edit: If for whatever reason you really need your macro to be in that macro list, you should make that parameter a variable in your macro and use an inputbox to specify it. That way when the user clicks the macro, they'll be prompted for the input and then the macro can run accordingly.

With regards to functions, you can have a function with parameters and use it as a formula in excel but as far as I'm aware they won't show up in the macro list either.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much, is great to have a definitive answer. Much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.