Question about a unique list in VBA by checking data inside of 2 columns

A

Avenarius

Hi all,

I have a question in terms of a unique list generation.

My list looks like:

Column A
Name1
Name2
Name3
Name1
Name1

Column B
Name4
Name2
Name3
Name1
Name1
Name2

and so on

The result I am looking for is a new spreadsheet containing:
Name1
Name2
Name3
Name4


Any ideas about how to get that ready?

Thank you in advance.

Cheers,
Avenarius
 
G

Guest

Lots of people ask for the macro

Sub mergecolumns()

Set OldSheet = ActiveSheet
With OldSheet
LastRowColA = Cells(Rows.Count, "A").End(xlUp).Row
Set ColARange = .Range(Cells(1, "A"), _
Cells(LastRowColA, "A"))

LastRowColB = Cells(Rows.Count, "B").End(xlUp).Row
Set ColBRange = .Range(Cells(1, "B"), _
Cells(LastRowColB, "B"))
End With

Worksheets.Add after:=ActiveSheet
ActiveSheet.Name = "Summary"

RowCount = 1
For Each cell In ColARange
If RowCount = 1 Then
Cells(RowCount, "A") = cell.Value
RowCount = RowCount + 1
Else
Set ColRange = Range(Cells(1, "A"), _
Cells(RowCount - 1, "A"))
Set c = ColRange.Find _
(what:=cell.Value, LookIn:=xlValues)
If c Is Nothing Then
Cells(RowCount, "A") = cell.Value
RowCount = RowCount + 1
End If

End If

Next cell

For Each cell In ColBRange
If RowCount = 1 Then
Cells(RowCount, "A") = cell.Value
RowCount = RowCount + 1
Else
Set ColRange = Range(Cells(1, "A"), _
Cells(RowCount - 1, "A"))
Set c = ColRange.Find _
(what:=cell.Value, LookIn:=xlValues)
If c Is Nothing Then
Cells(RowCount, "A") = cell.Value
RowCount = RowCount + 1
End If

End If

Next cell

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top