Merge 2 columns and remove duplicates

production123

New Member
Joined
Mar 11, 2019
Messages
3
Hi, i’ve started using VBA at my work and have stumbled on what seems like a very simple problem, but I am unable to see any answers that suit my needs on here.

Basically, I have Column A on sheet 1, and Column A on sheet2, and they have about 30,000 rows on each. I want to copy and paste, as values, both columns into Sheet3, and remove duplicates. Currently i have VBA doing this but it’s an unedited, recorded macro and takes 3 mins for it to work.

Is there a faster way of doing this?
 

Some videos you may like

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,530
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
As it's a recorded macro the answer is yes :)
Although with general questions like this, it normally helps if you supply the code your using ;)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,530
Office Version
  1. 365
Platform
  1. Windows
Depending how many unique values you have try
Code:
Sub production123()
   Dim Cl As Range
   Dim Ws1 As Worksheet, Ws2 As Worksheet
   
   Set Ws1 = Sheets("Sheet1")
   Set Ws2 = Sheets("Sheet2")
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws1.Range("A2", Ws1.Range("A" & Rows.Count).End(xlUp))
         .Item(Cl.Value) = Empty
      Next Cl
      For Each Cl In Ws2.Range("A2", Ws2.Range("A" & Rows.Count).End(xlUp))
         .Item(Cl.Value) = Empty
      Next Cl
      Sheets("Sheet3").Range("A2").Resize(.Count).Value = Application.Transpose(.Keys)
   End With
End Sub
 

production123

New Member
Joined
Mar 11, 2019
Messages
3
Thanks - I have managed to simplify it down to the below - on sheet3 I have columns B-Q which have formula that look up other contents in sheet1 and 2 which works fine.

Columns A on both sheets is a formula which creates a unique identifer from different formats. The most data I have seen in one tab is 27855, it varies every day which is why I have dragged the formula down to row30000 to make sure.

Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False

'
' Position_rec Macro
'

'
Sheets("Sheet1").Range("A2:A30000").Copy
Sheets("Sheet3").Range("A2").PasteSpecial xlPasteValues

Sheets("Sheet2").Range("A2:A30000").Copy
Sheets("Sheet3").Range("A30002").PasteSpecial xlPasteValues

Columns("A:Q").Select
ActiveSheet.Range("$A:$Q").RemoveDuplicates Columns:=1, Header:=xlNo

Sheets("Sheet3").Range("$A$1:$Q$60003").AutoFilter Field:=11, Criteria1:="<>0", _
Operator:=xlAnd

Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True

End Sub
 

production123

New Member
Joined
Mar 11, 2019
Messages
3
Depending how many unique values you have try
Code:
Sub production123()
   Dim Cl As Range
   Dim Ws1 As Worksheet, Ws2 As Worksheet
   
   Set Ws1 = Sheets("Sheet1")
   Set Ws2 = Sheets("Sheet2")
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws1.Range("A2", Ws1.Range("A" & Rows.Count).End(xlUp))
         .Item(Cl.Value) = Empty
      Next Cl
      For Each Cl In Ws2.Range("A2", Ws2.Range("A" & Rows.Count).End(xlUp))
         .Item(Cl.Value) = Empty
      Next Cl
      Sheets("Sheet3").Range("A2").Resize(.Count).Value = Application.Transpose(.Keys)
   End With
End Sub

Thank you, this works a lot faster than the current! My last message shows what I had, I have a filter on which removes 0s from column Q on sheet3 as well but I will add that in!

Great help thanks
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,530
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,368
Messages
5,528,276
Members
409,814
Latest member
Leon_Al

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top