How do I prevent duplicate entries across sheets

kmdavidson

New Member
Joined
Apr 15, 2004
Messages
4
I have searched and searched but haven't come up with an answer to this:

Does anyone know how to prevent duplicate entries when using more than one sheet. e.g. I want to set it up so that I can only use a number once. So if the number was already entered on sheet 2 and I try to enter it on sheet 1, I get an error message. I know it has to do with data validation and defining a range, but I can't get the syntax and instructions right. Thanks.

I have been using Microsoft's Knowledge Base Article 213185 as a model.
 
(Mrexcel was inaccessible to me for some time, what's happening ?)
I had about the same code as DRJ but added
Target.Activate (before ELSE)
when you want to type another number you don't have te click again in the cell

regards,
Erik
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
erik.van.geit said:
(Mrexcel was inaccessible to me for some time, what's happening ?)

same thing happens to me every day for a few minutes. I guess we are not supposed to know what is going on during that time.
 
Upvote 0
Hi,
Been trying to use the same code but "Subscript out of range pops up " . Only difference in mine is that the range to be validated is sheet3, B18:b217 , to be checked from sheet2, b18:217 . The code i am using is :
Code:
Private Sub Worksheet_Change(ByVal Target As Range)


If Not Target.Column = 2 Then Exit Sub 'Only work on column B


    If Application.WorksheetFunction.CountIf(Sheets("Sheet3").Range("$B$18:$B$217"), Target.Value) + Application.WorksheetFunction.CountIf(Sheets("Sheet2").Range("$B$18:$B$218"), Target.Value) > 1 Then
        MsgBox "You have entered a duplicate number, please try again"
        Target.ClearContents
    Else
End If


End Sub
 
Upvote 0
Hello All, I am new to Macros and all this, I am wondering however if there is a way to create a code that ranges across 8 worksheets and Columns / Rows A40 to W40?
 
Upvote 0

Forum statistics

Threads
1,215,579
Messages
6,125,646
Members
449,245
Latest member
PatrickL

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