I've been trying to combine to separate change events in my VBA code. The first allows users to insert hyperlinks into specific columns and the second enables multi-select drop-downs in other cells.
The problem is I can't get them to work together. One always over rides the other. I've read other threads and have tried to combine my code and am sitting right now with the code below.
Does anyone have any ideas?
The problem is I can't get them to work together. One always over rides the other. I've read other threads and have tried to combine my code and am sitting right now with the code below.
Does anyone have any ideas?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Selection.Count = 1 Then
If Not Intersect(Target, Range("AG:AI")) Is Nothing Then
ActiveSheet.Protect AllowInsertingHyperlinks:=True
End If
End If
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
Dim lUsed As Long
ActiveSheet.Unprotect Password:="IPAC"
'If Selection.Count > 1 Then GoTo exitHandler
On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
'On Error GoTo exitHandler
'If rngDV Is Nothing Then GoTo exitHandler
Select Case Target.Column
Case 18, 20, 23, 27, 29, 44, 46
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 newVal = "" Then
'do nothing
Else
lUsed = InStr(1, oldVal, newVal)
If lUsed > 0 Then
If oldVal = newVal Then
Target.Value = ""
ElseIf Right(oldVal, Len(newVal)) = newVal Then
Target.Value = Left(oldVal, Len(oldVal) - Len(newVal) - 1)
Else
Target.Value = Replace(oldVal, newVal & vbLf, "")
End If
Else
Target.Value = oldVal & vbLf & newVal
End If
End If
End If
Case Else:
End Select
ActiveSheet.Protect
exitHandler:
Application.EnableEvents = True
End Sub