How do I assign a macro to a button and pass an argument to the macro?
Sorry if this is too simple but I have had no luck searching forums for the answer.
ReBoot
How do I assign a macro to a button and pass an argument to the macro?
Sorry if this is too simple but I have had no luck searching forums for the answer.
ReBoot
Last edited by VBA Noob; 03-01-2008 at 04:14 PM.
You can have the macro pop up an InputBox or Application.InputBox to request the argument.
I was hoping I could just pass the argument without the user having to enter it. Each button they press will have it's own value for the argument. The values will not change once it is set up.
I saw an answer that showed entering this code when assigning the macro.
Here it is,
To assign your macro Macro1, passing the number 16 as the parameter, to a button on your worksheet , in the Tools->Assign Macro dialog, type
'Macro1 16'
but when I try that, it thinks the macro name is Macro1 16.
ReBoot
A macro attached to a button can pass a variable to another called macro
![]()
Please Login or Register to view this content.
Please Read Forum Rules Before Posting
Wrap VBA code by selecting the code and clicking the # icon or Read This
How To Cross Post politely
Top Excel links for beginners to Experts
If you are pleased with a member's answer then use the Scales icon to rate it
If my reply has assistedor failed to assist you
I welcome your Feedback.
I was hoping I wouldn't have to code so many macros, and would be able to pass the argument when the button is pressed. I have 18 buttons.
To pass an argument when pressing a button in an Excel sheet.
When you right click an Excel button to assign a macro, enter the macro name and argument as such. 'Macro1(1)'
Note the single quotes around the whole thing.
This example will call the macro Macro1, and pass it the number 1.
I hope this will help someone else.
ReBoot
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks