Duplicate value

mks

Board Regular
Joined
Aug 28, 2009
Messages
173
Hi ,

I have the following code, but I want to amend this code to work for column C10:C400 only.

Code -

Private Sub Worksheet_Change(ByVal Target As Range)

Dim TRow As Long
Dim TCol As Long
Dim Foundcell As Range
Dim Ans As VbMsgBoxResult

TRow = Target.Row
TCol = Target.Column
If Target.Cells.Count > 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
If WorksheetFunction.CountIf(Cells(TCol).EntireColumn, Target.Value) > 1 Then
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
If Target.Column <> 3 Then Exit Sub
<o:p> </o:p>
If WorksheetFunction.CountIf(Cells(TCol).EntireColumn, Target.Value) > 1 Then
Set Foundcell = Columns(TCol).Find(what:=Target.Value, after:=Cells(1, TCol), LookIn:=xlValues, Lookat:=xlPart, searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=False)
<o:p> </o:p>
Ans = MsgBox("Duplicate Job # : " & Foundcell.Address & " - Press OK to Delete", vbNo)
If Ans = vbYes Then Exit Sub Else ActiveCell.Offset(0, -1).ClearContents

End If
End If
End Sub
Thanks
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
try like this.

Code:
[/FONT]
[FONT=Courier New]Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Intersect(Target, Range("C10:C400")) Is Nothing Then
 'You conditions here...
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top