UserForm listbox won't initialize

korhan

Board Regular
Joined
Nov 6, 2009
Messages
215
Hello Mr.Excel Community,

I have a really simple question which I couldn't figure out by myself.
My listbox won't initialize no matter what I have tried. I have tried to initialize the listbox when I open the form, I have also tried a click event and none of them worked.

Here is my test code for Form Initialization
Sub QuoteForm_Initialize()
' Fill the list box
Me.lstItemNames.AddItem "Orange"
End Sub

And test code for ListBox click event:
Private Sub lstItemNames_Click()
Me.lstItemNames.AddItem "Orange"
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
This line:
Code:
Sub QuoteForm_Initialize()
should be:
Code:
Sub UserForm_Initialize()

You don't change it to match the name of the form. ;)
 
Upvote 0
This line:
Code:
Sub QuoteForm_Initialize()
should be:
Code:
Sub UserForm_Initialize()

You don't change it to match the name of the form. ;)
To follow up on Rory's comment... you should never type an event header out yourself... always click the left-hand drop down above the code type-in area and select the object from there, then select the event header itself from the right-hand drop down and let VB supply the correct event procedure header for the object for you.
 
Upvote 0
Thank you so much for the answers. I thought that the behavior would be the same as in VB.
I guess there are some fundamental differences between VB and VBA.
Thank you all.
 
Upvote 0

Forum statistics

Threads
1,216,747
Messages
6,132,483
Members
449,729
Latest member
davelevnt

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