Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
LIST WITH FACILITY TO ADD TO THIS
hello friends
can we create a listbox or anything like that with a few values to select and if a value is selected we must be able to add some more words to it eg. suppose the list box values are A,B,C and D If A is selected add €ś 100 apples€ť to it ...like that THANK YOU... -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...mming/200910/1 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
LIST WITH FACILITY TO ADD TO THIS
Do you mean a dropdown list in a worksheet cell, or do you mean a listbox on
a userform? When the selection is subsequently edited, should that change the list of valid items for the listbox (so that next time, 'A 100 apples' appears in the dropdown list)? If you mean a dropdown list in a cell, you can create it using data validation. The best way is to enter the valid choices in contiguous cells on another sheet. Select all those cells and assign them a range name (for example, MyList). In the cell where you want the dropdown list, select Data Validation. On the Settings tab, change the Allow setting to List and ener =MyList as the source. On the Error Alert tab, uncheck the box to 'Show error alert after invalid data is entered'. Click OK to close the Data Validation dialog. Now you can select an entry from MyList, then edit it without an error message. This doesn't change the list of valid entries for the cell - it is still defined by MyList. To "permanently" change A to 'A 100 apples' you would edit the cell in MyList that contains A. If you mean a listbox on a userform, here is a simple example. I created a userform (UserForm1) with a combobox (ComboBox1) and 2 textboxes (TextBox1 and TextBox2) on it. I sized and placed them so that TextBox1 exactly covers ComboBox1. When TextBox1 is double-clicked it is hidden and the combobox is shown. Selecting a value from the combobox puts that value in TextBox1, where it can be edited. IF you don't want to update the list of items in the combobox, this is all you need. To update the list of combobox item, when you exit TextBox1 the code checks if it matches the last item selected from the combobox + more text. If yes, the last item selected from the combobox is removed from list of combobox items and the current value of TextBox1 is added. The code is crude but may give you a starting point, if this is what you are trying to do. Option Explicit Public CurrItm As String Public ChgFlag As Boolean Private Sub ComboBox1_Change() CurrItm = ComboBox1.Value Me.ComboBox1.Visible = False Me.TextBox1.Value = ComboBox1.Value Me.TextBox1.Visible = True ChgFlag = True End Sub Private Sub TextBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) Me.TextBox1.Visible = False Me.ComboBox1.Visible = True ChgFlag = False End Sub Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) Dim tmp As String, x As Long tmp = TextBox1.Value On Error Resume Next If Left(TextBox1.Value, Len(CurrItm)) = CurrItm And _ (TextBox1.Value < ComboBox1.Value) And (ChgFlag = True) Then For x = 0 To ComboBox1.ListCount - 1 If ComboBox1.List(x) = CurrItm Then Me.ComboBox1.RemoveItem x Me.ComboBox1.ListIndex = -1 End If Next x TextBox1.Value = tmp Me.ComboBox1.AddItem TextBox1.Value CurrItm = TextBox1.Value End If End Sub Private Sub UserForm_Initialize() Me.ComboBox1.AddItem "A" Me.ComboBox1.AddItem "B" Me.ComboBox1.AddItem "C" Me.ComboBox1.AddItem "D" ChgFlag = False End Sub Hope this helps, Hutch "evelin via OfficeKB.com" wrote: hello friends can we create a listbox or anything like that with a few values to select and if a value is selected we must be able to add some more words to it eg. suppose the list box values are A,B,C and D If A is selected add €ś 100 apples€ť to it ...like that THANK YOU... -- Message posted via OfficeKB.com http://www.officekb.com/Uwe/Forums.a...mming/200910/1 . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
List Box with lookup facility | Excel Worksheet Functions | |||
Spelling Facility | New Users to Excel | |||
Search Facility | Excel Programming | |||
'Group by' facility? | Excel Programming | |||
search facility | Excel Programming |