0

I created a user form that asks the user to fill in 3 parameters (textbox) + having OK button.

I also have a sub procedure, public sub Analyze (actionName as String, endStr as String, startStr as String) which I call with different parameters.

I wish that upon clicking on Ok button on my user form, a new button will be created (this can easily be done by activesheet.buttons.add) and will be assigned to a new macro - the Analyze procedure with the parameters from the user form --> so i need to create each time a new sub calling Analyze sub with different parameters.

Is it possible? how can I do that?

6
  • 1
    Possible duplicate of How to add a command button in VBA? Commented May 9, 2018 at 8:42
  • nope, it explains how to create a button and assign it to a macro - this i know. My problem is that my sub is dynamic, i wish to call it with different input parameters, taken from my user form. Commented May 9, 2018 at 8:54
  • A button can only call a sub without parameters. So probably better save these parameters in a sheet and use them from there? Commented May 9, 2018 at 8:58
  • I'm able to save them to the sheet, did that. But how can i create now new macro calling Analyze with those parameters? Commented May 9, 2018 at 9:01
  • Eg if you have a button on each row of parameters you can link all buttons with the same procedure and use ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row to get the row of the clicked button and read the parameters from this row then. Commented May 9, 2018 at 9:05

0

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.