NANABANANA0505
New Member
- Joined
- Nov 30, 2016
- Messages
- 1
Hello,
I am having a difficult time with a VBA code for allowing filtering capabilities on a protected sheet with multiple drop down. The sheet itself allows users to select multiple items from drop downs on columns 12-16; however, users have been unable to use basic filtering, sorting, and Find functions on the essential 1-11 columns. As you can imagine, this has become really frustrating when attempting to find a single case in a list of over 1000. I would really appreciate it if someone would look over the code and offer suggestions. Thank you!
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDV As Range, oldVal As String, newVal As String, lUsed As Long
Sheets("Active").Unprotect Password:="CaseTracking"
On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler
If rngDV Is Nothing Then GoTo exitHandler
If Intersect(Target, rngDV) Is Nothing Then
'do nothing
Else
Application.EnableEvents = False
newVal = Target.Value
Application.Undo
oldVal = Target.Value
Target.Value = newVal
If Target.Column = 12 Or Target.Column = 14 Or Target.Column = 15 Or Target.Column = 13 Or Target.Column = 16 Then
If oldVal = "" Then
'do nothing
Else
If newVal = "" Then
'do nothing
Else
lUsed = InStr(1, oldVal, newVal)
If lUsed > 0 Then
If Right(oldVal, Len(newVal)) = newVal Then
Target.Value = Left(oldVal, Len(oldVal) - Len(newVal) - 2)
Else
Target.Value = Replace(oldVal, newVal & ", ", "")
End If
Else
Target.Value = oldVal & ", " & newVal
End If
End If
End If
End If
End If
exitHandler:
Sheets("Active").Protect Password:="CaseTracking"
Application.EnableEvents = True
End Sub
I am having a difficult time with a VBA code for allowing filtering capabilities on a protected sheet with multiple drop down. The sheet itself allows users to select multiple items from drop downs on columns 12-16; however, users have been unable to use basic filtering, sorting, and Find functions on the essential 1-11 columns. As you can imagine, this has become really frustrating when attempting to find a single case in a list of over 1000. I would really appreciate it if someone would look over the code and offer suggestions. Thank you!
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDV As Range, oldVal As String, newVal As String, lUsed As Long
Sheets("Active").Unprotect Password:="CaseTracking"
On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler
If rngDV Is Nothing Then GoTo exitHandler
If Intersect(Target, rngDV) Is Nothing Then
'do nothing
Else
Application.EnableEvents = False
newVal = Target.Value
Application.Undo
oldVal = Target.Value
Target.Value = newVal
If Target.Column = 12 Or Target.Column = 14 Or Target.Column = 15 Or Target.Column = 13 Or Target.Column = 16 Then
If oldVal = "" Then
'do nothing
Else
If newVal = "" Then
'do nothing
Else
lUsed = InStr(1, oldVal, newVal)
If lUsed > 0 Then
If Right(oldVal, Len(newVal)) = newVal Then
Target.Value = Left(oldVal, Len(oldVal) - Len(newVal) - 2)
Else
Target.Value = Replace(oldVal, newVal & ", ", "")
End If
Else
Target.Value = oldVal & ", " & newVal
End If
End If
End If
End If
End If
exitHandler:
Sheets("Active").Protect Password:="CaseTracking"
Application.EnableEvents = True
End Sub