Forward not Backwards

kev6264

New Member
Joined
Jun 16, 2006
Messages
44
I have this procedure that works great, but if I select a two-letter code in a cell that precedes another cell, the procedure allows the duplicate. How can I turn this into a forward and backwards checker?

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Target.Column <> 4 Then Exit Sub
    If Application.WorksheetFunction.CountIf(Range("$D$2:$D" & Target.Row), Target) > 1 Then
        MsgBox "You have chosen a duplicate sine. Please try again"
        Application.EnableEvents = False
        Application.Undo
        Application.EnableEvents = True
    End If
End Sub
 
only two-letter-combinations ?

allowing alpha-numerics you have only 36x36=1296 combinations while you're already at row 2512
did you try filling in more characters ?

try out your code on a new sheet
 
Upvote 0

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
The light just came on... I have the cells validated against a list.. Guess where the list is copied? Column 4 down below my entry sheet. Boy, do I feel really dumb now :rolleyes: . Erik, thanks for sticking with me this long. Works great now that I moved my validation list. DAAAH
 
Upvote 0

Forum statistics

Threads
1,215,583
Messages
6,125,664
Members
449,247
Latest member
wingedshoes

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