Find duplicate combination in list and highlight cell

sadonnie

New Member
Joined
Dec 17, 2018
Messages
13
I have the following table as an example. Here is what I am trying to accomplish using Worksheet_Change(ByVal Target As Range) <---I assume this is the most logical approach to invoking the logic

This is all in 1 sheet (say Sheet1). I have a list of Applications in Col A (the same application can be listed many times in this column). Col B can be ignored. Columns C, D, and E will either be left blank or have a value of 1.

Using the Supply Chain example, when I get to row 4 and I put a value of 1 in Col E, it should invoke Worksheet_Change(ByVal Target As Range) and I am trying to get the code to identify that the Application Name + Col E value is already equal to a value of 1 (combo exists in Row 2 already). Therefore it shades the cell in E4 and displays a note to the user since this is a duplication scenario.

Same would apply if user entered a value of 1 in Col C or D and the logic validates that the App Name + Col C or D combination already exists in the sheet.

Any suggestions or recommendations is greatly appreciated.

1666157075728.png
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try:
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lr&, count&, cell As Range
With Target
    lr = Cells(Rows.count, "A").End(xlUp).Row
    count = WorksheetFunction.CountIfs(Range("A2:A" & lr), Cells(.Row, "A"), _
    Range(Cells(2, .Column), Cells(lr, .Column)), Target)
End With
If Intersect(Target, Range("C2:E" & lr)) Is Nothing Then Exit Sub
    For Each cell In Range("A2:A" & lr)
        If cell.Value = Cells(Target.Row, "A").Value Then
            With Cells(cell.Row, Target.Column)
                .ClearComments
                .Interior.Color = xlNone
                If count > 1 Then
                    .AddComment
                    .Comment.Visible = False
                    .Comment.Text Text:="Person already assigned, pls remove"
                    .Interior.ColorIndex = 46
                End If
            End With
        End If
    Next
End Sub
 
Upvote 0
Thank you for your assistance. This works perfectly and much more simplified code then what I had initially developed.
Much appreciated for your support!
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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