Need to Protect Sheet, allow multiple selections on drop-down lists, and be able to filter at same time.

bluewomble88

New Member
Joined
Jun 7, 2017
Messages
3
I am really bad with VBA and would appreciate some help.

I have a sheet that has multiple columns (let's say A through to G) and it's critical that some columns (e.g. B) are protected as they return data automatically using VLOOKUP. My problem is that columns D and G have drop-down lists assigned via Data Validation and I need the user to be able to make more than 1 selection. I have found some code that does this but only for one column, not both. How do I fix this?

The other issue is that even with one column working, as soon as I protect the sheet, I can't filter the columns because of this code. I am losing my mind TBH.

I need to be able to have the sheet protected, columns D and G to allow multiple selections in the drop-down lists, and the data to be filtered if I want. Can this be done?

Private Sub Worksheet_Change(ByVal Target As Range)

'Code by Sumit Bansal from Online Excel Tips & Tutorials
' To allow multiple selections in a Drop Down List in Excel (without repetition)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Target.Column = 4 Then
ActiveSheet.Unprotect
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 & vbNewLine & Newvalue
Else:
Target.Value = Oldvalue
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
ActiveSheet.Protect
Application.EnableEvents = True
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,223,276
Messages
6,171,139
Members
452,381
Latest member
Nova88

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