Question about Listbox

blanch2009

New Member
Joined
Feb 24, 2009
Messages
6
Hello.
I'm using the code below in a worksheet:
I found the tutorial on YouTube and the dropdown list feature multiple select of values.
It works perfectly!! Except for one thing. When I click to protect the sheet, the multiple selection feature goes away. I'm able
to select a single value but not multiple.

I took the check mark off on the Select Locked Cells under the Protect tab.
I did this to all input cells so I can tab through the sheet and not have tab into an empty cell.
I hope I'm explaining myself clearly.
This is my first attempt in VBA.
If I unprotect the sheet then the tab through doesn't work.

Any help would really be appreciated and thank you in advance.

Don

Option Explicit

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Code by Sumit Bansal from [URL='https://trumpexcel.com']Online Excel Tips & Tutorials[/URL]
' To Select Multiple Items from a Drop Down List in Excel
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
        If Target.Address = "$I$5" Or Target.Address = "$L$11" Then
           
  If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
    GoTo Exitsub
  Else: If Target.Value = "" Then GoTo Exitsub Else
    Application.EnableEvents = False
    Newvalue = Target.Value
    Application.Undo
    Oldvalue = Target.Value
      If Oldvalue = "" Then
        Target.Value = Newvalue
      Else
        If InStr(1, Oldvalue, Newvalue) = 0 Then
            Target.Value = Oldvalue & ", " & Newvalue
      Else:
        Target.Value = Oldvalue
      
        End If
    End If
  End If
End If

Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True

End Sub
 
Last edited by a moderator:

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try it like
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Code by Sumit Bansal from [URL='https://trumpexcel.com']Online Excel Tips & Tutorials[/URL]
' To Select Multiple Items from a Drop Down List in Excel
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
        If Target.Address = "$I$5" Or Target.Address = "$L$11" Then

 If Target.Value = "" Then GoTo Exitsub Else
    Application.EnableEvents = False
    Newvalue = Target.Value
    Application.Undo
    Oldvalue = Target.Value
      If Oldvalue = "" Then
        Target.Value = Newvalue
      Else
        If InStr(1, Oldvalue, Newvalue) = 0 Then
            Target.Value = Oldvalue & ", " & Newvalue
      Else:
        Target.Value = Oldvalue

        End If
    End If
  End If


Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True

End Sub
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0
You're welcome & thanks for the feedback.
I'm referring to the same list box with this question. Again, thank you for your help.
I would like to add an item in the actual list box and have it update the list I'm pulling the data from.
Right now, using Data Validation, if you add something that's not in the list, it throws an error.
Can or is there a work around for this to allow the entry?
Thank you
Don
 
Upvote 0
As that is a totally different question, you need to start a new thread. Thanks
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top