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
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
The initialize should be
Code:
Private Sub UserForm_Initialize()
 
Upvote 0
Hey,

thanks for the reply. When I change it to Private Sub Userform_Initialize

- I get this error:
"Run Time error 424
Object Required"

If I do it as
Code:
Private Sub Userform1_Initialize


There is no error. BUT the comboboxes don't populate :(


The initialize should be
Code:
Private Sub UserForm_Initialize()
 
Upvote 0
Yeah, so when I put it in, what I did was insert the userform > right click, hit view code for the userform....Then added in the initialize Sub.

Code:
 Private Sub Userform_Initialize()
With Combobox1
.additem.... etc...etc..

end with
end sub


Is the initialize sub in the userform object?
 
Upvote 0
Do you have a combobox called ComboBox1?
If you put
Code:
Option Explicit
At the very top of the module (before any subs) & try to open the userform, what message do you get?
 
Upvote 0
I was actually about to respond and address that question.

So my code is in two places.
1. The command button code to trigger the userform is within the VB editor and Sheet114.
2. The userform code is within the userform > right click > view code - in the VB editor.

Now I do have Module1 ....but I don't have any code in Module 1....Is that where all the code should be?



Do you have a combobox called ComboBox1?
If you put
Code:
Option Explicit
At the very top of the module (before any subs) & try to open the userform, what message do you get?
 
Upvote 0
Oh and I put Option Explicit at the top of all the sub routines...and this time I got,
Compiler Error - Variable Not Defined


Do you have a combobox called ComboBox1?
If you put
Code:
Option Explicit
At the very top of the module (before any subs) & try to open the userform, what message do you get?
 
Upvote 0
That means that you don't have anything on the userform called ComboBox1
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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