7

Typically when referencing a userform control value in Excel VBA I would enter something to the effect of radiobutton.value

However, I want to be able to use a string as the name of the user control. The idea behind this would be to dynamically be able to generate the control name and reference a value from it.

For example I may want to reference ctradiobutton.value one time, and etradiobutton.value the next, these controls already exist on the form, I just want to reference a different name of the control from a string created on the current iteration.

3
  • 2
    I'm pretty sure that you can't change the code name of a control once it's on a userform Commented Jun 6, 2014 at 14:06
  • You'll get a runtime error 382, it's not possible to set the control's .Name property at run-time. Perhaps you can use another property like .Caption to control your process flow. Commented Jun 6, 2014 at 14:09
  • @Kyle I think I may have been unclear, I am not trying to change the control name on the form, but rather get the value from it in my code Commented Jun 6, 2014 at 14:09

1 Answer 1

15

Like this (where Me is the UserForm)

Me.Controls("TextBox1").Value
Sign up to request clarification or add additional context in comments.

Comments

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.