Welcome
How can I implement the same command and prevent the same value from repeating in multiple rows?
Example
A5:G5 ; A8:G8 ; A11:G11
How can I implement the same command and prevent the same value from repeating in multiple rows?
Example
A5:G5 ; A8:G8 ; A11:G11
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim strTargetColumn As String
Dim nTargetRow As Integer
Dim nLastRow As Integer
Dim strMsg As String
strTargetColumn = Split(Target.Address(, False), "$")(0)
nTargetRow = Split(Target.Address(, False), "$")(1)
nLastRow = ActiveSheet.Range(strTargetColumn & ActiveSheet.Rows.Count).End(xlUp).Row
For nRow = 5 To nLastRow
If nRow <> nTargetRow Then
If ActiveSheet.Range(strTargetColumn & nRow).Value = Target.Value Then
strMsg = "The value has been entered in the same column!"
MsgBox strMsg, vbExclamation + vbOKOnly, "Duplicate Values"
Target.Select
Exit For
End If
End If
Next
End Sub