Listbox fillcode?where to put?

Lexje

Active Member
Joined
Jul 6, 2004
Messages
264
Hi Everybody!

I'm trying to fill a listbox that sits on a userform, via code.
If I put the code in the userform, it doesn't pick up the additem.
When I put the code in a module, it's allright.

Why can't it be put in the userform code?

Thanks for your help!!

Erwin
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi

Have you put the code in the userform Activate event, not the Click event, which is what is defaulted to when you double-click the userform?

HTH

Alan
 
Upvote 0
I'm following an example of J-Walk's book.
I haven't opened a code pane by clicking anywhere. I've just opened the userform code pane.
My idea was the listbox should be filled when initializing the userform.

Thanks for your help!

Erwin
 
Upvote 0
But I do see where you're heading.
The listbox will sit on the third page of a multipage userform.
Should I opt for the MultiPage Change event or ?

Thanks
 
Upvote 0
Erwin

Post your code.

Does it look like this:

Private Sub Userform_Initialize()
End Sub
 
Upvote 0
Hi Norie, thanks for hopping in;
I've tried several things, also on a separate test workbook.

Code:
Private Sub MultiPage1_Change()
With frmCountry_Tab.MultiPage1.Pages(2).lst_Years
    With frmCountry_Tab.lst_Years
        .RowSource = "Country!Years"
        
'        .AddItem "1999"
'        .AddItem "2000"
    End With
'    frmCountry_Tab.MultiPage1.Pages(2).Show
End With
End Sub

This is what I have now;
Even when I add this section to the UserForm_Initialize() section, it doesn't fill.

Also, how do I get the scrollbar at the right vertical side instead of at the bottom?
I see you already answered on my other question too; what needs to be shown in the listbox is, 1999; 2000; ...; 2009. And the listbox is definitely wider than 4 digits...
Nevertheless, horizontally positioned at the bottom...

Thanks!
Erwin
 
Upvote 0
Why are you setting the RowSource and then trying to add items?

add this section to the UserForm_Initialize() section

What do you mean by add?

Also, how do I get the scrollbar at the right vertical side instead of at the bottom?
This is answered in another post. You really should try to post only once for eact topic ie this post is about the listbox and so is the other.

You can ask more than one question per post.
 
Upvote 0
Norie,

I appreciate your comments, but:
I have tremendously positive reaction on this forum, therefore, will also try to help wherever, whenever possible...
I have experienced however that sometimes you get better response and get things clearer when posting small questions.
And as it happens, I'm experimenting about to get things done, and try different ways, different things, and so come sometimes, different questions somehow related...
Thanks for your understanding..

As you can see, I'm trying to get things working, so because the .AddItem did not work, I tried setting the RowSource.
That's why these AddItems are uncommented, but it shouldn't make a difference on how to get the code initiated, not?

Thanks a lot,

Erwin
 
Upvote 0
When I play around with the shape of the listbox on the userform, indeed the scrollbars react; I even have two scrollbars. But to have only one at the righthand side (Andrew) I have to make it only 2 items (lines) high and about 10-12 characters wide?

Does this make sense? Can it be controlled?
 
Upvote 0
Here's my initialize code;
By add, I mean that I have copy/pasted the relevant lines at the bottom of the initialize code.

Code:
Sub frmCountry_Tab_Initialize()
    cboYear.Value = ""
    cboCountry.Value = ""
    txtSource.Value = ""
    txtYear.Value = ""
    txtYearSource.Value = ""
    txtGDP.Value = ""
    txtGDP_growth.Value = ""
    txtPopulation.Value = ""
    txtInflation.Value = ""
    txt_GDP_capita = " "
    txtMemo.Value = ""
    txtYearSource.Value = ""
    MultiPage1.Value = "0"
'    MultiPage1.Value = 1
    cboUpdate.Visible = False
    cboCancel.Visible = False
    txt100P.Visible = False
    txt200P.Visible = False
    txt300P.Visible = False
    txt400P.Visible = False
    txt500P.Visible = False
    txt510P.Visible = False
    txt600P.Visible = False
    txt700P.Visible = False
    txt900P.Visible = False
    txtYearSource_pres.Visible = False
    cmb1.Visible = False
    cmb2.Visible = False
    cmb3.Visible = False
    cmb4.Visible = False
    cmb5.Visible = False
    cmb6.Visible = False
    cmb7.Visible = False
    cmb8.Visible = False
    cmb9.Visible = False
    cmb10.Visible = False
    With frmCountry_Tab.MultiPage1.Pages(2).lst_Years
    With frmCountry_Tab.lst_Years
        .RowSource = "Country!Years"
        
'        .AddItem "1999"
'        .AddItem "2000"
    End With
'    frmCountry_Tab.MultiPage1.Pages(2).Show
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,630
Members
449,041
Latest member
Postman24

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