How do you populate a form list box from a range of cells e.g. A1:A10?
How do you populate a form list box from a range of cells e.g. A1:A10?
i find it easier to do it naming the range you want to populate.
and then you can use the following code
![]()
Please Login or Register to view this content.
Excellent, that has solved part one,
When a user selects Item 1 in the ComboBox I want the label next to it to read the Item Code.
The item code would be in the adjacent cell to the description.
Are you using the ListBox on a userform/
Why are you using a listBox and a label when a listbox can have multicolumns and so display the contents of each column?
Hope that helps.
RoyUK
--------
For Excel Tips & Solutions, free examples and tutorials why not check out my web site
Free DataBaseForm example
well... im going to show you how you could write this code, but im pretty sure you could do the same thing going a different way.
for instance, listbox1 is populated from range A1:A10, and the cells you want to display are the correspondent cell on collumn B.
i guess this solves your problem. i didnt try this code to see if it works properly, so if you have problems let us know.![]()
Please Login or Register to view this content.
Hi Roy,
I have used a combo box. Would a list box be more suitable? I am trying to achieve a form whereby;
If a user selects Item1 the code for the item is auto populated onto the form. All the items are listed in sheet1 with Item Description in Column A and Item Code in Column B.
What would be the most efficient way to achieve this?
marcospaterson;
I get a compile error when changing the value of the combobox;
Method or data member not found
I still don't know whether you are using a UserForm or the Forms Controls from the Forms menu. Also, you originally stated that you are using a listBox.
Hi Roy i am using a UserForm and I was using a combox. Sorry for the confusion
Well I would use a listBox as originally stated. Set the Column Count to two. Then load the listbox
![]()
Please Login or Register to view this content.
Hi Roy,
I seem to have got a little confused and can't get this to work. I need a combo box really as I don't like the way list boxes show the data.
I get an errorwith Label9.Value =, Method or Data member not found
![]()
Please Login or Register to view this content.
Don't use the select method it is inefficient, use the .Find function.
Your error is caused because a label does not have a Value Property, but a Caption.
![]()
Please Login or Register to view this content.
Thanks Roy,
Only other problem now is that it will only work when my active sheet1 is selected. So if I am viewing Sheet2 when the form runs i get an error.
Method 'Range' of object '_worksheet' failed.
I have fixed it using 'Sheet1.Select' before the rng selection. Would you say thats an appropriate fix?
Many Thanks for you help
Sam Williams
I wouldn't select sheets unnecessarily. You need to specify the sheet in your code and when loading the combobox. Can you attach a zipped workbook example?
I have attached the xls file
Here's some amended code for your UserForm
The prescribe button overwrites previous entries, is this correct?![]()
Please Login or Register to view this content.
Hi roy,
Thanks for that change and yoru help.
The prescribe button is meant to over write as i have yet to develop the function that clears the information after it has been exported.
Many Thanks for your help
Credit to this forum.
Sam Williams
Glad it helped, post back for further help.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks