Problem with - UserForm Initialize

excelenergy

Board Regular
Joined
Jun 7, 2012
Messages
142
Hello

I have a command button, located on my spreadsheet. The code for the command button is in the vba editor within the name of the sheet - which is sheet114.

When the command button is clicked, a userform pops up. The userform has combo-boxes on it.

The userform is failing to initialize, and populate the combox boxes. Here is the code for the user-form initialize sequence and the drop downs, I was curious why isn't it initializing and populating? It should be, I'm not getting any kind of errors from VBE.

Code for the Command Button:

Code:
Private Sub CommandButton1_Click()
UserForm1.Show
End Sub





Code for Initialization of the Form:
Code:
Private Sub UserForm1_Initialize()
With ComboBox1
 .AddItem "Telephones"
 .AddItem "Computers"
 .AddItem "Monitors"
End With
End Sub




This is the code for combo-box1:

Code:
Private Sub ComboBox1_Change()
Dim index As Interger
 index = ComboBox1.ListIndexComboBox2.Clear

Select Case index
     
Case Is = 0
With ComboBox2
.AddItem "CISCO
.AddItem "Bell"
.AddItem "Oracle"
        End With
     
     
     Case Is = 1
         With ComboBox2
.AddItem "Sony"
.AddItem "Hewlet Packard"
.AddItem "Dell"
End With

Case Is = 2
With ComboBox2
.AddItem "Acer"
.AddItem "Dell"
.AddItem "Samsung"
End With

End Select
End Sub
 
Fantastic all, that worked. I just don't know whats so different about your code than my original. I fixed the spelling mistake. Maybe it was the way I did the line break or something.

Much appreciated. Thank you for helping solve this!


The userform code should be
Code:
Private Sub UserForm_Initialize()
   With ComboBox1
    .AddItem "Telephones"
    .AddItem "Computers"
    .AddItem "Monitors"
   End With
End Sub

Private Sub ComboBox1_Change()
   Dim index As Integer
   index = ComboBox1.ListIndex
   ComboBox2.Clear
   
   Select Case index
      Case Is = 0
         With ComboBox2
            .AddItem "CISCO"
            .AddItem "Bell"
            .AddItem "Oracle"
         End With
      Case Is = 1
         With ComboBox2
            .AddItem "Sony"
            .AddItem "Hewlet Packard"
            .AddItem "Dell"
         End With
      Case Is = 2
         With ComboBox2
            .AddItem "Acer"
            .AddItem "Dell"
            .AddItem "Samsung"
         End With
   End Select
End Sub
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
after the userform pops up - the boxes still don't populate.

Just to be clear, I think the two issues keep popping up:

Command Button to Call the form should be


Code:
Private Sub CommandButton1_Click()
UserForm1.Show
End Sub

wheras the initialize should be:


Code:
Private Sub UserForm_Initialize()

The difference being you need the specific name (UserForm1) to call the form, but the generic name (UserForm) to initialize it.

Edit: Glad you got it figured out!
 
Last edited:
Upvote 0
That makes sense. I definitely see what you are saying...thanks for the help. I guess it was just silly amateur errors on my part. I appreciate the help with the troubleshooting.

Just to be clear, I think the two issues keep popping up:

Command Button to Call the form should be


Code:
Private Sub CommandButton1_Click()
UserForm1.Show
End Sub

wheras the initialize should be:


Code:
Private Sub UserForm_Initialize()

The difference being you need the specific name (UserForm1) to call the form, but the generic name (UserForm) to initialize it.

Edit: Glad you got it figured out!
 
Upvote 0
In the event anyone ever comes across this problem...Hotabae and Fluffs solutions worked perfectly.

I wanted to add my two cents though. Hotabae originally said add a break after Cisco...I actually had to add breaks at the end of every ".additem" line. Then the combo boxes populated.


Thanks to everyone who contributed. The solution provided worked perfectly

Just to be clear, I think the two issues keep popping up:

Command Button to Call the form should be


Code:
Private Sub CommandButton1_Click()
UserForm1.Show
End Sub

wheras the initialize should be:


Code:
Private Sub UserForm_Initialize()

The difference being you need the specific name (UserForm1) to call the form, but the generic name (UserForm) to initialize it.

Edit: Glad you got it figured out!
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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