Macro to extract unique records

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,595
Office Version
  1. 2021
Platform
  1. Windows
I have data in Col on Sheet "Imported Data" . I want to copy the unique records to sheets

When running the macro the first time, It extracts the unique records. However when running a second time, it extracts all the the records in Col C on nsheet "Imported Data"


It would be appreciated if someone could amend my code


Code:
 Sub Extract_Unique_Branches()
Sheets("Branches").Select
Dim LR1 As Long
LR1 = Cells(Rows.Count, "A").End(xlUp).Row

Range("a1:A" & LR1).ClearContents

Sheets("Imported Data").Select
Dim LR As Long
LR = Cells(Rows.Count, "A").End(xlUp).Row


Application.ScreenUpdating = False
Sheets("Imported Data").Range("C1:C" & LR).Copy Destination:=Sheets("Branches").Range("A1")
Sheets("Branches").Range("A2:A" & LR1).RemoveDuplicates Columns:=1, Header:=xlNo
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
hello,
wrong row count,use
Code:
Option Explicit

Sub Extract_Unique_Branches()
    Dim LR1 As Long
    Dim LR As Long
    With Sheets("Branches")
        LR1 = .Cells(Rows.Count, "A").End(xlUp).Row
        .Range("a1:A" & LR1).ClearContents
    End With
    With Sheets("Imported Data")
        LR = .Cells(Rows.Count, "A").End(xlUp).Row
    End With
    Application.ScreenUpdating = False
    Sheets("Imported Data").Range("C1:C" & LR).Copy Destination:=Sheets("Branches").Range("A1")
    Sheets("Branches").Range("A2:A" & LR).RemoveDuplicates Columns:=1, Header:=xlNo
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,260
Members
452,627
Latest member
KitkatToby

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