User Form Combo Box Not Filling?

updog

New Member
Joined
Feb 21, 2019
Messages
4
Afternoon all,

As a VBA beginner, I'm currently having an issue with my user form where the combo box isn't populating with the options "I Shares" and "S Shares".
I suspect that it may be an issue due to the start of the code in terms of the userform_initialize? If I'm being honest I'm not familiar with what this even does. However, I have tried a similar code in another dummy spreadsheet where I've added fruits into a combo box and this has seemed to work?

I would be very grateful if someone could point me in the right direction!
The below is just a section of the code: [the userform is called ISShareClassForm and the combo box is called ISShareClassComboBox]

Private Sub ISShareClassForm_Initialize()

'Empty IShareClassComboBox
ISShareClassComboBox.Clear

'Fill ISShareClassComboBox
With ISShareClassComboBox
.AddItem "I Shares"
.AddItem "S Shares"
End With

And this is the code (that worked) whcich I have used as a dummy with fruits:


Private Sub UserForm_Initialize()

With ComboBox1
.AddItem "Banana"
.AddItem "Orange"
.AddItem "Pear"
.AddItem "Grapes"
End With


End Sub




Much appreciated,
updog
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
And this is the code (that worked) whcich I have used as a dummy with fruits:
Much appreciated,
updog

Rich (BB code):
Private Sub UserForm_Initialize()

With ComboBox1
    .AddItem "Banana"
    .AddItem "Orange"
    .AddItem "Pear"
    .AddItem "Grapes"
End With


End Sub

Hi welcome to forum

You have answered your own question - The event is ALWAYS UserForm_Initialize regardless of the name you give your userform.

Dave
 
Last edited:
Upvote 0
Hi Dave,

Thank you for your welcome and reply.
Would UserForm_Initialize be an issue if I had 2 user forms? Not sure if that questions makes sense but I'm not particularly sure how to explain what I mean!

Regards,
updog
 
Upvote 0
Each userform will have its own events -

From the userforms code page you should see two dropdown boxes at the top - In left dropdown select Userform, then the right hand one will provide you with all its events available. You can only have ONE of each event in your form.

You may find this helpful:https://www.homeandlearn.org/the_form_initialize_event.html

Dave
 
Upvote 0
Try this:
Code:
Private Sub UserForm_Initialize()
'Modified  2/22/2019  3:27:29 AM  EST
    With ComboBox1
        .Clear
        .AddItem "Banana"
        .AddItem "Orange"
        .AddItem "Pear"
        .AddItem "Grapes"
    End With

    With ISShareClassComboBox
        .Clear
        .AddItem "I Shares"
        .AddItem "S Shares"
    End With
End Sub
 
Upvote 0
Thank you both for your time and help - very much appreciated.
Just for a quick update (if you're interested), I also realized that I had made another error (in addition to the UserForm_Initialize) in terms of naming my text boxes and referring to another name in the code e.g. it would be "ShareClassTextBox1" in the form and I would refer to it as "ShareClassTextBox", which would contribute to the error message.

Thanks again.

Kind regards
updog
 
Upvote 0
Just as a side note I always suggest keeping all Control Names like TextBoxs and Comboboxes

Names as their default name Like TextBox1 and TextBox2

This way if you ever want to have 20 TextBoxes and have their values put into cells on your sheet.
You can use a loop like this.

Code:
Private Sub CommandButton2_Click()
'Modified  2/22/2019  4:46:17 AM  EST
Dim ctrl As Control
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row + 1
    For i = 1 To 5 ' Meaning you have 5 Texboxes and want their values enter into your sheet
        Cells(Lastrow, i).Value = Me.Controls("TextBox" & i).Value
        Me.Controls("TextBox" & i).Value = ""
    Next
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,442
Members
448,898
Latest member
drewmorgan128

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