-
Nov 13th, 2006, 03:09 PM
#1
Thread Starter
New Member
Creating a drop down list box in Excel (a beginner)
I am a beginner of VBA. I searched the forum for the answer of my question but I have a hard time understanding the terminology in the posts.
Basically, I just want to create a drop down list box in VBA. The topics that will appear in the list box are already fixed and will never ever change in the future. The user will pick a topic from the list and the code will take appropriate action accordingly. Can someone tell me how to do this in layman's terms? Or could you lead me to a reading?? I have been googling about this but couldn't find a tutorial.
Thanks!
-
Nov 13th, 2006, 03:26 PM
#2
Re: Creating a drop down list box in Excel (a beginner)
if it is a fixed list you can add the items to the listbox at design rather than in code, then just use code to do whatever depending on which item is selected
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 13th, 2006, 03:31 PM
#3
Re: Creating a drop down list box in Excel (a beginner)
Why are you posting the same question again and again?
Pradeep
-
Nov 13th, 2006, 08:54 PM
#4
Thread Starter
New Member
Re: Creating a drop down list box in Excel (a beginner)
westconn1, thanks for your response. How can I add items to the listbox in "design rather than code". Thanks in advance!!
-
Nov 14th, 2006, 04:09 AM
#5
Re: Creating a drop down list box in Excel (a beginner)
what program are you using listbox?
and what version?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 14th, 2006, 05:43 AM
#6
Junior Member
Re: Creating a drop down list box in Excel (a beginner)
do you want to create the listbox / combobox on an excel worksheet or create it on a form?
if its on a worksheet
http://www.techonthenet.com/excel/qu...eate_combo.php
otherwise,
create a form within VBA name it form1 or what ever you want,
create a combo box on the form
name it:
listBox1 or what ever you want
Code:
Private Sub form1_Activate()
listBox1.AddItem "Item1"
listBox1.AddItem "Item2"
listBox1.AddItem "Item3" 'etc
End Sub
this will run when the user changes the combo box
Code:
Private Sub listBox1_Change()
Dim tempValue As String
tempValue=listBox1.Value
If tempValue = "item1" Then
'do this
ElseIf tempValue = "item2" Then
'do this
Else
'do this
End If
End Sub
Hope this helps!
-
Nov 14th, 2006, 02:46 PM
#7
Re: Creating a drop down list box in Excel (a beginner)
Hi I was just wondering if you need to create that in a worksheet then there is a simple way of doing it rather than using VB.
Use Excel Validation
Steps
1) In any Column, type the name of the topics. Say in cell A1, A2, A3, A4, A5 type "apples", "oranges", "grapes", "guava" and "Melon" respectively
2) select the cell where you want the list to populate say B1
3)click on the menu data->validation
4)Under the Settings tab select "lists" as the validation criteria
5) click the little red arrow in the source "prompt"
6) select the range i.e A1:A5 and press enter twice
your list is ready! if you click on B1, you will see your list will drop down :-)
Last edited by Siddharth Rout; Nov 14th, 2006 at 02:48 PM.
Reason: spelling mistake
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
May 7th, 2007, 09:15 PM
#8
New Member
Re: Creating a drop down list box in Excel (a beginner)
that's a good idea koolsid
I have a problem though, I have created a drop down list, however, it refers to a non-unique list, so I have duplicate options. It does not look really good, especially if I have a lot of multiple similar options. Due to the nature of the data, I can not force the source of entries only contain unique data.
So, I am looking for a solution to generate a unique validation list (ie. neglecting duplicate entries). Any ideas?
Thanks.
-
May 8th, 2007, 03:47 AM
#9
Re: Creating a drop down list box in Excel (a beginner)
If you are refering to creating the list in Excel sheet then the best way to do it is create a pivot table (check the link in my signature) and then use that list for the validation... this way you will always get one entry rather then duplicate entries...
In the layout part of the pivot table, keep the say 'names' field in the row and the 'count of names' in the data.
Hope this helps...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|