agonysWeeper
Board Regular
- Joined
- Feb 4, 2011
- Messages
- 146
Hello,
Looking for some help on this vba code from somewhere in google, I am almost no knowledge on VBA so I'm trying to do some additional logic.
so when the contract number has existing record on the 'J' column, the message will pop up and click OK, after clicking the OK button and trying to delete the contract number on that cell (using keyboard delete), the message will pop up again, so I need not to have the pop up when deleting the number.
The below code run as well in other column and I just want it to run in column J.
Looking for some help on this vba code from somewhere in google, I am almost no knowledge on VBA so I'm trying to do some additional logic.
so when the contract number has existing record on the 'J' column, the message will pop up and click OK, after clicking the OK button and trying to delete the contract number on that cell (using keyboard delete), the message will pop up again, so I need not to have the pop up when deleting the number.
The below code run as well in other column and I just want it to run in column J.
Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row = 1 Then Exit Sub ' IF ITS A HEADER, DO NOTHING.
On Error GoTo ErrHandler
Application.ScreenUpdating = False
Dim myDataRng As Range
Dim cell As Range
' WE WILL SET THE RANGE (SECOND COLUMN).
Set myDataRng = Range("J1:J" & Cells(Rows.Count, "J").End(xlUp).Row)
For Each cell In myDataRng
cell.Offset(0, 0).Font.Color = vbBlack ' DEFAULT COLOR.
' LOCATE DUPLICATE VALUE(S) IN THE SPECIFIED.
If Application.Evaluate("COUNTIF(" & myDataRng.Address & "," & cell.Address & ")") > 1 Then
MsgBox "This contract number has existing record above, please just update the existing record and Open the status - If this is alt request due to different term, or need to have separate request, please proceed."
Exit Sub
'cell.Offset(0, 0).Font.Color = vbRed ' CHANGE COLOR TO RED.
End If
Next cell
Set myDataRng = Nothing
ErrHandler:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Last edited: