Valeu, Alexandre!
Obrigado!
Como o meu Intervalo é ("B5:P14") e preciso da Validação Por Linhas: ("B5:P5") até ("B14:P14") ,
adaptei a função.
Obs: Ficou feio e pesado, mas funcionou.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Or IsEmpty(Target(1, 1)) Then Exit Sub
If Not Intersect(Target, Range("B5:P14")) Is Nothing Then
If WorksheetFunction.CountIf(Range("B5:P5"), Target) > 1 Then
MsgBox Target & " Já existe"
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
If WorksheetFunction.CountIf(Range("B6:P6"), Target) > 1 Then
MsgBox Target & " Já existe"
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
If WorksheetFunction.CountIf(Range("B7:P7"), Target) > 1 Then
MsgBox Target & " Já existe"
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
If WorksheetFunction.CountIf(Range("B8:P8"), Target) > 1 Then
MsgBox Target & " Já existe"
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
If WorksheetFunction.CountIf(Range("B9:P9"), Target) > 1 Then
MsgBox Target & " Já existe"
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
If WorksheetFunction.CountIf(Range("B10:P10"), Target) > 1 Then
MsgBox Target & " Já existe"
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
If WorksheetFunction.CountIf(Range("B11:P11"), Target) > 1 Then
MsgBox Target & " Já existe"
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
If WorksheetFunction.CountIf(Range("B12:P12"), Target) > 1 Then
MsgBox Target & " Já existe"
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
If WorksheetFunction.CountIf(Range("B13:P13"), Target) > 1 Then
MsgBox Target & " Já existe"
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
If WorksheetFunction.CountIf(Range("B14:P14"), Target) > 1 Then
MsgBox Target & " Já existe"
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
End Sub
Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel
Postado : 10/06/2016 10:02 am