This forum has been moved to TeachExcel.com
Ask all future questions in the New Excel Forum.
ExcelKey
I discovered that after entering a few Call Signs to see if things worked properly, and deleting them I had to copy a unused cell and paste it where I had deleted the cells in order to work again.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
'limit checking to col A below row 6
If Target.Column <> 1 Or Target.Row < 7 Or Target.Count <> 1 Then Exit Sub
'establish range to check for duplicate
Set rng = Range("A7:A" & Cells(Rows.Count, 1).End(xlUp).Row)
'prevent this event from calling itself
Application.EnableEvents = False
'if target is not empty
If Target.Value <> "" Then
'count how many times target appears in rng
If Application.WorksheetFunction.CountIf(rng, Target.Value) = 1 Then
'it's targets first occurrance, put date/time into adjacent cell
Target.Offset(0, 1).Value = Now
'remove any existing cell fill color
Target.Interior.ColorIndex = 0
Else
'it's a duplicate
'put date/time in adjacent cell
Target.Offset(0, 1).Value = Now
'indicate it's a duplicate
Range("A3").Value = Target.Value
'color the just entered duplicates cell
Target.Interior.ColorIndex = 36
End If
'if target is empty ie:been deleted
Else
'remove date/time
Target.Offset(0, 1).Value = ""
'clear duplicate indication
Range("A3").Value = ""
'remove cell color
Target.Interior.ColorIndex = 0
End If
'make sure events are re-enabled
Application.EnableEvents = True
End Sub
Return to Macros and VBA Questions
Users browsing this forum: Google [Bot] and 242 guests