Column A Column B Column C (desired result) Column D (desired result)
001 002 001 A
002 003 004 A
003 005 005 B
004 006 007 A
006 008 008 B
007 009 015 A
009 016 A
015
016
I am looking to identify number in Column C that is Unique and write a comment "Column Name" (to which Column data set the unique data belongs) in Column D. Appreciate your help for excel formula and/or VBA code.
Sub Demo1()
Dim V, S$(), Rg As Range, R&
V = [{"A","B"}]
With [A1].CurrentRegion.Columns("A:B")
.Offset(, 2).Clear
ReDim S(1 To .Cells.Count, 1)
For Each Rg In .SpecialCells(xlCellTypeConstants)
If Application.CountIf(.Cells, Rg.Value2) = 1 Then
R = R + 1
S(R, 0) = Rg.Value2
S(R, 1) = V(Rg.Column)
End If
Next
End With
If R Then [C1:D1].Resize(R).Value2 = S
End Sub
Do you like it ? So thanks to click on bottom left star icon « ★ Add Reputation » !
Last edited by Marc L; 08-07-2019 at 05:25 PM.
Reason: optimization following post #4 …
Another way in order to keep the text cell formatting and the column order :
PHP Code:
Sub Demo2()
Dim F$, C%, V, R&
Application.ScreenUpdating = False
With [A1].CurrentRegion.Columns("A:B")
.Item("C:D").Clear
F = "TRANSPOSE(IF(COUNTIF(" & .Address & ",#)=1,ROW(#)))"
For C = 1 To 2
For Each V In Filter(Evaluate(Replace(F, "#", .Item(C).Address)), False, False)
R = R + 1
Cells(V, C).Copy Cells(R, 3)
Cells(R, 4).Value2 = Chr$(64 + C)
Next
Next
End With
Application.ScreenUpdating = True
End Sub
Do you like it ? So thanks to click on bottom left star icon « ★ Add Reputation » !
Bookmarks