Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Marcia3641
 
Posts: n/a
Default 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
  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default

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



  #3   Report Post  
dominicb
 
Posts: n/a
Default


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

  #4   Report Post  
Marcia3641
 
Posts: n/a
Default

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


  #5   Report Post  
Chip Pearson
 
Posts: n/a
Default

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






  #6   Report Post  
dominicb
 
Posts: n/a
Default


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

  #7   Report Post  
Marcia3641
 
Posts: n/a
Default

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


  #8   Report Post  
dominicb
 
Posts: n/a
Default


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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Excel ActiveX listbox controls programmer123 Excel Discussion (Misc queries) 0 July 7th 05 10:30 PM
UserForm Data to Spreadsheet Andy Tallent Excel Discussion (Misc queries) 2 June 22nd 05 04:51 PM
Data Validation Cell - Move to UserForm thom hoyle Excel Worksheet Functions 0 April 28th 05 12:23 AM
Cell Content from UserForm Not Retained D.Parker Excel Discussion (Misc queries) 3 April 27th 05 04:56 PM
How can I run a macro in the background whilst a UserForm is visib cdb Excel Discussion (Misc queries) 3 February 10th 05 06:58 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"