@Saulo
Boa tarde,
Fiz o que solicitou, agora precisa fazer alguns testes de uso para ver se esta de acordo com o funcionamento adequado.
Código: Selecionar todosPrivate Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
On Error GoTo tr_ERR
Select Case Target.Column
Case 1
'******************************************************************
'Código Deixado Pelo Ex-Colaborador
'******************************************************************
Dim r, LR As Long
Excel.Application.ScreenUpdating = False
Excel.Application.EnableEvents = False
If Target.Value = "" Then
Target.Offset(, 1).Value = "": Target.Offset(, 1).Validation.Delete
Else: [W:W] = ""
With Sheets("BANCO DE DADOS")
On Error Resume Next
.ShowAllData
On Error GoTo 0
LR = .Cells(Rows.Count, 1).End(3).Row
.Range("A8:F" & LR).AutoFilter 1, Target.Value
.Range("B10:B" & LR).Copy: [W1].PasteSpecial xlValues
.ShowAllData
r = Application.Transpose(Range("W1:W" & Cells(Rows.Count, 23).End(3).Row))
Target.Offset(, 1).Value = "": Target.Offset(, 1).Validation.Delete
If Application.CountA([W:W]) > 1 Then
Target.Offset(, 1).Validation.Add Type:=xlValidateList, Formula1:=Join(r, ",")
Else: Target.Offset(, 1) = [W1]
End If
End With
[W:W] = ""
Excel.Application.ScreenUpdating = True
Excel.Application.EnableEvents = True
End If
Case 2
'******************************************************************
'Código Desenvolvido no Forum Guru Por Basole - 08 Abr 2022 às 18:25
'******************************************************************
Dim rng As Range
Dim c As Range
Set rng = Range("B4:B" & Cells(Rows.Count, 1).End(xlUp).Row)
If Not Excel.Application.Intersect(Target, rng) Is Nothing Then
For Each c In rng
If Excel.Application.CountIfs(Cells(c.Row, 1), _
Target.Offset(, -1), _
Cells(c.Row, 2), Target.Value) > 0 And _
c.Row <> Target.Row Then
MsgBox "Já existe a combinação, Selecione outro valor", 16, "Aviso"
Excel.Application.EnableEvents = False
Target.Value = ""
Excel.Application.EnableEvents = True
Exit For
End If
Next
End If
Set rng = Nothing
End Select
tr_ERR:
Excel.Application.ScreenUpdating = True
Excel.Application.EnableEvents = True
End Sub