Macro to extract unique records

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
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,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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