How to prevent duplicates.....

Keand31

New Member
Joined
Jul 25, 2011
Messages
4
Hi all.

A small problem I just can't seem to wrap my head around...
I am trying to create a planner and I've tried countif, Datavalidation and conditional formating but when ever I think I am close no dice.

My challenge is this:
I have X number of people who all have to have lunch together each month but only one on one.

So if Person 1 has lunch with Person 2 they can't have lunch with person 3, 4, 5, and 6 that month.

My sheet would look something like this:
ABCDE
1NameJanuaryFebruaryMarchEtc..
2Name 1Name 2
3Name 2Name 5
4Name 3Name 1
5Name 4Name 3
6Name 5Name 4

<tbody>
</tbody>

What I need is to somehow check if the same combination exist in the same month?
IE. February where Name 2 & 4 both have a appointment with Name 5.

Like I said I just canøt wrap my head around it..
What gets me everytime is that I need to somehow check if name X is present in Column Month and the value can be either 0, 1 then true and if more than 1 then Error.

There might be a simple solution to this but I just can't see it :(

Sincerely
Kenneth Andersen
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
If VBA is OK :

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lr&, col&, rng As Range, area As Range, x%
If Target.count > 1 Then Exit Sub
Target.Interior.Color = xlNone
If Target = "" Then Exit Sub
col = Target.Column
lr = Cells(Rows.count, "A").End(xlUp).Row
Set rng = Cells(2, col).Resize(lr - 1).SpecialCells(xlCellTypeConstants)
Set rng = Union(rng.Offset(, -col + 1), rng)
For Each area In rng.Areas
    x = x + WorksheetFunction.CountIf(area, Target)
    If x > 1 Then
        MsgBox "Duplicate"
        Target.Interior.Color = vbRed
        Exit For
    End If
Next
If x < 2 Then
    x = 0
    For Each area In rng.Areas
        x = x + WorksheetFunction.CountIf(area, Target(1, -col + 2))
        If x > 1 Then
            MsgBox "Duplicate"
            Target.Interior.Color = vbRed
            Exit For
        End If
    Next
End If
End Sub
 
Upvote 0
Thank you so much Footoo - Works like a charm.
You have just saved me a lot of headache. :biggrin:

Sincerely
Kenneth
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,936
Members
449,094
Latest member
teemeren

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