ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   UserForm Listbox in VBC (https://www.excelbanter.com/excel-discussion-misc-queries/36327-userform-listbox-vbc.html)

Marcia3641

UserForm Listbox in VBC
 
Hi:
I added a listbox to my form, but I can't figure out how to add the list of
items.
--
Marcia3641

Bob Phillips

With Listbox1
.Additem "You"
.AdfdItem "Me"
.AddItem "Someone else"
End With

--
HTH

Bob Phillips

"Marcia3641" wrote in message
...
Hi:
I added a listbox to my form, but I can't figure out how to add the list

of
items.
--
Marcia3641




dominicb


Good evening Marcia3641

You need to put some code such as this behind the userform:

Private Sub UserForm_Initialize()
With ListBox1
.AddItem "Item 1"
.AddItem "Item 2"
.AddItem "Item 3"
.AddItem "Item 4"
End With
End Sub

This code assumes that your listbox is called ListBox1.

HTH

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=388914


Marcia3641

Thanks Bob and dominicb. Here is what I have:
Private Sub ListBoxAgeGrp_Click()
..AddItem "Under 25"
..AddItem "26 - 34"
..AddItem "35 - 42"
..AddItem "43 - 55"
..AddItem "56 - 62"
..AddItems "63 and over"
End With
End Sub
Does it make a difference that mine says "click" instead of "initialize"?
Also, how do I check and see if it worked. I tried going to run usferform but
it didn't show the list that I created. Boy this is hard stuff!
--
Marcia3641


"dominicb" wrote:


Good evening Marcia3641

You need to put some code such as this behind the userform:

Private Sub UserForm_Initialize()
With ListBox1
.AddItem "Item 1"
.AddItem "Item 2"
.AddItem "Item 3"
.AddItem "Item 4"
End With
End Sub

This code assumes that your listbox is called ListBox1.

HTH

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=388914



dominicb


Hi Marcia

It does make a difference in that the "Initialize" bit will do
something to the userform when it first opens up, so the Listbox will
be populated immediately, whereas yours will not populate until you
click on the button you have named ListBoxAgegrp. Also, the command
AddItem should only be preceded by a single ".", not two as shown
below.

To run your userform set up a small macro such as:

Sub Test()
Userform1.Show
End Sub

and then call the macro, which will run your userform.

Finally, do stick with it! It does seem really baffling at first but
it does get easier. If you really need a hand try considering buying a
book (http://j-walk.com/ss/books/index.htm) to explain the whole concept
in detail. The satisfaction of finishing a project is worth it...!

Good luck

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=388914


Chip Pearson

The Click event in your code will run only when the list box is
clicked. The list will be populated at that time. In the code
that dominicb wrote, the list box will be populated when the
userform is initialized, generally when it is shown. Use his code
rather that yours.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Marcia3641" wrote in
message
...
Thanks Bob and dominicb. Here is what I have:
Private Sub ListBoxAgeGrp_Click()
.AddItem "Under 25"
.AddItem "26 - 34"
.AddItem "35 - 42"
.AddItem "43 - 55"
.AddItem "56 - 62"
.AddItems "63 and over"
End With
End Sub
Does it make a difference that mine says "click" instead of
"initialize"?
Also, how do I check and see if it worked. I tried going to run
usferform but
it didn't show the list that I created. Boy this is hard stuff!
--
Marcia3641


"dominicb" wrote:


Good evening Marcia3641

You need to put some code such as this behind the userform:

Private Sub UserForm_Initialize()
With ListBox1
.AddItem "Item 1"
.AddItem "Item 2"
.AddItem "Item 3"
.AddItem "Item 4"
End With
End Sub

This code assumes that your listbox is called ListBox1.

HTH

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile:
http://www.excelforum.com/member.php...o&userid=18932
View this thread:
http://www.excelforum.com/showthread...hreadid=388914





Marcia3641

Here is the code I have for my listbox.

Private Sub ListBoxLoanType_Click()
With ListBoxLoanType
..AddItem 'Fixed'
..AddItem 'Interest Only'
..AddItem 'ARM'
End With
End Sub


When I changed it to "initialize" I kept getting a message that it was
ambiguious and then the drop down object box at the top of the code screen
kept changing back to "general" instead of "ListBoxLoanType". Then when I go
to test the form, I am unable to click on the list boxes that I have on the
form. I can tab through all the boxes that are text but I am having no luck
with the three boxes that are list-boxes. Does anything look wrong to you? I
am at my wits end, because this is the only item I am having trouble with on
my form.
--
Marcia3641


"dominicb" wrote:


Hi Marcia

It does make a difference in that the "Initialize" bit will do
something to the userform when it first opens up, so the Listbox will
be populated immediately, whereas yours will not populate until you
click on the button you have named ListBoxAgegrp. Also, the command
AddItem should only be preceded by a single ".", not two as shown
below.

To run your userform set up a small macro such as:

Sub Test()
Userform1.Show
End Sub

and then call the macro, which will run your userform.

Finally, do stick with it! It does seem really baffling at first but
it does get easier. If you really need a hand try considering buying a
book (http://j-walk.com/ss/books/index.htm) to explain the whole concept
in detail. The satisfaction of finishing a project is worth it...!

Good luck

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=388914



dominicb


Hi Marcia

Take a look at my reply to yuo other thread.

http://www.excelforum.com/showthread...=1#post1039668

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=388914



All times are GMT +1. The time now is 06:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com