Add value in cell next to a duplicate

pook_666

Board Regular
Joined
Aug 16, 2018
Messages
94
Hi team,

Hopefully a quick one for you geniuses.

I have a column of duplicate and non-duplicate values. I want to add a comment in the cell next to each if there is a duplicate or not.

For an easy example, see below where I have the below numbers in column A and I want to put in column B next to each number either "Yes" if there is a duplicate or "No" if there isn't.

1605686243330.png

Either a formula inserted directly into column B cells or VBA would be fine if anyone can help!

Thanks!
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
maybe

ValueYN
1No
2Yes
3No
2Yes
5No
6No
7Yes
7Yes
7Yes
10No
11No
12Yes
12Yes
14No

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    Index = Table.AddIndexColumn(Source, "Index", 1, 1),
    Group = Table.Group(Index, {"Value"}, {{"Count", each Table.RowCount(_), type number}, {"All", each _, type table}}),
    YN = Table.AddColumn(Group, "YN", each if [Count] = 1 then "No" else "Yes"),
    Expand = Table.ExpandTableColumn(YN, "All", {"Index"}, {"Index"}),
    Sort = Table.Sort(Expand,{{"Index", Order.Ascending}}),
    TSC = Table.SelectColumns(Sort,{"YN"})
in
    TSC
 
Last edited:
Upvote 0
Formula in cell B1
=IF(COUNTIF(A:A,A1)>1,"Yes","No")
and then copied down
 
Upvote 0
Solution
@sandy666 - sorry, I'm not entirely sure what you've done? Or where?
1. update your profile about Excel version and OS, don't forget to scroll down and hit SAVE
2. this is Power Query and it depends on what Excel version you have

more info
 
Last edited:
Upvote 0
Hi
What about
VBA Code:
Sub test()
    Dim a As Variant
    Dim i As Double
    a = Range("a1:a" & Cells(Rows.Count, 1).End(xlUp).Row).Resize(, 2)
    With CreateObject("scripting.dictionary")
        For i = 1 To UBound(a)
            If a(i, 1) <> 0 Then
                If Not .exists(a(i, 1)) Then
                    .Add a(i, 1), "No"
                Else
                    .Item(a(i, 1)) = "YES"
                End If
            End If
        Next
        For i = 1 To UBound(a)
            If .exists(a(i, 1)) Then
                a(i, 2) = .Item(a(i, 1))
            End If
        Next
        Cells(1, 1).Resize(UBound(a), 2) = a
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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