philaboast
New Member
- Joined
- Dec 12, 2009
- Messages
- 2
Hi- Would like suggestions on how to compare arrays of data for exact matches and receive outputs of cell references instead of a cumulative number of matches using =MATCH
Excel Workbook | |||||||
---|---|---|---|---|---|---|---|
A | B | C | D | E | |||
1 | INPUT 1 | INPUT 2 | DESIRED OUTPUT | ||||
2 | a | a | a | ||||
3 | a | c | c | ||||
4 | a | e | |||||
5 | b | f | |||||
6 | c | f | |||||
7 | d | g | |||||
8 | d | h | |||||
1 |
Option Explicit
Sub GetUniquesMultipleColumns()
Dim Rng As Range, Dn As Range
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
Do
On Error Resume Next
Set Rng = Nothing
Set Rng = Application.InputBox("Click the top-most item of the next column to compare. If no more, click Cancel.", Type:=8)
On Error GoTo 0
If Rng Is Nothing Then Exit Do
Set Rng = Range(Rng, Cells(Rows.Count, Rng.Column).End(xlUp))
For Each Dn In Rng
If Not .Exists(Dn.Value) Then .Add Dn.Value, Dn.Next.Value
Next
Loop
Set Rng = Application.InputBox("Click the cell where you want the unique list to begin.", Type:=8).Resize(.Count)
Rng = Application.Transpose(Array(.Keys))
End With
If MsgBox("Do you want to sort the unique list?", vbYesNo, "Sort List?") = vbYes Then Rng.Sort Key1:=Rng(1), Order1:=xlAscending, Header:=xlNo
End Sub
Excel Workbook | |||||||
---|---|---|---|---|---|---|---|
A | B | C | D | E | |||
1 | INPUT 1 | INPUT 2 | OUTPUT | ||||
2 | a | a | |||||
3 | b | ||||||
4 | b | c | |||||
5 | c | d | |||||
6 | d | 1 | |||||
7 | 1 | 2 | |||||
8 | 2 | 3 | |||||
9 | 3 | 4 | |||||
10 | |||||||
11 | |||||||
1 |
Excel Workbook | |||||||
---|---|---|---|---|---|---|---|
A | B | C | D | E | |||
1 | INPUT 1 | INPUT 2 | OUTPUT | ||||
2 | a | a | 1 | ||||
3 | b | 2 | |||||
4 | b | c | 3 | ||||
5 | c | d | 4 | ||||
6 | d | 1 | |||||
7 | 1 | 2 | a | ||||
8 | 2 | 3 | b | ||||
9 | 3 | 4 | c | ||||
10 | d | ||||||
11 | |||||||
1 |
Option Explicit
Sub GetUniquesMultipleColumns()
Dim Rng As Range, Dn As Range
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
Do
On Error Resume Next
Set Rng = Nothing
Set Rng = Application.InputBox("Click the top-most item of the next column to compare. If no more, click Cancel.", Type:=8)
On Error GoTo 0
If Rng Is Nothing Then Exit Do
Set Rng = Rng.Parent.Range(Rng, Rng.Parent.Cells(Rows.Count, Rng.Column).End(xlUp))
For Each Dn In Rng
If Not .Exists(Dn.Value) Then .Add Dn.Value, Dn.Next.Value
Next
Loop
Set Rng = Application.InputBox("Click the cell where you want the unique list to begin.", Type:=8).Resize(.Count)
Rng = Application.Transpose(Array(.Keys))
End With
If MsgBox("Do you want to sort the unique list?", vbYesNo, "Sort List?") = vbYes Then Rng.Sort Key1:=Rng(1), Order1:=xlAscending, Header:=xlNo
End Sub