Initialize a UserForm with custom name

Joined
Nov 27, 2019
Messages
18
Office Version
  1. 365
  2. 2013
  3. 2010
Platform
  1. Windows
Hi, I need to create a UserForm containing a ComboBox initialized with two pre-defined values. The UserForm code looks like this:
VBA Code:
Private Sub UserForm_Initialize()
    ComboBox1.AddItem "Value_A"
    ComboBox1.AddItem "Value_B"
End Sub

If I run the code, the results are as expected ONLY if the name of the UserForm is exactly 'UserForm'. Once I rename it to, say, 'UserForm2' (in the code and in the definitions tab simultaneously) it fails to initialize the ComboBox properly - a single blank value is seen in the drop-down list.

Please advise how this can be fixed.

Best regards,
Dmitry
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi,
You can give your userform any legal name required but the Event you show is ALWAYS UserForm_Initialize regardless of the name you have given it.
You must not rename this or any of the other events associated with a userform.

Dave
 
Upvote 0
Hi,
You can give your userform any legal name required but the Event you show is ALWAYS UserForm_Initialize regardless of the name you have given it.
You must not rename this or any of the other events associated with a userform.

Dave
Dear Dave,

Got it. As you could easily deduce from my post, I'm really new to UserForms :)

Thanks for help!
 
Upvote 0

Forum statistics

Threads
1,215,758
Messages
6,126,717
Members
449,332
Latest member
nokoloina

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