The code checks to see if the cell has data validation list, and then gets the name of the list. Private Sub Worksheet_Selection Change(By Val Target As Range) Dim rng DV As Range Dim old Val As String Dim new Val As String Dim str List As String On Error Resume Next Application. Special Cells(xl Cell Type All Validation) On Error Go To exit Handler If rng DV Is Nothing Then Go To exit Handler If Not Intersect(Target, rng DV) Is Nothing Then If Target. When the form opens, the Initialize code sets the source for the listbox, based on the data validation list in the active cell Private Sub cmd OK_Click() Dim str Sel Items As String Dim l Count List As Long Dim str Sep As String Dim str Add As String Dim b Dup As Boolean On Error Resume Next str Sep = ", " With DV For l Count List = 0 To . The file is in xlsm format, so enable macros when you open the file.
NOTE: This technique does not work for delimited lists that are entered directly into the data validation dialog box. There is also a single selection version of the file, that lets you pick one item to enter in the active cell.
how do i check if an item is selected or not in my listbox?
so i have a button remove, but i only want that button to execute if an item is selected in the list box. I'd prefer if this validation occurred on the server side. If you parse as usual then the result will be quite unexpected.
All the selected items are added to the cell, separated by a comma and space character.
Then, click the arrow, and select an item to fill the cell.
Instead of allowing only one choice from the drop down, you can use a bit of programming, and allow multiple selections.
You may want to go with the early-break out approach based on your prob desc & the fact that List Box.
Selected Index will return -1 if nothing is selected.