Removing duplicates a column.

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,280
Office Version
  1. 2013
Platform
  1. Windows
Hello,
Column A has multiple ID numbers(only digit numbers), but also on same column there are blanks rows and also there are text data's like headers.
Is it possible to get only the ID numbers into the another worksheet (Sheet2 column A) after removing to duplicates?
Many Thanks
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I would recommend copying the column to Sheet2.
Then sort it, and all text entries and numeric entries will be separated.
Then you can easily see and delete all the text entries.
You can then use Excel's built-in "Remove Duplicates" functionality to remove the numeric duplicates.

Then you should be left with just the unique numeric values!
 
Upvote 0
I would recommend copying the column to Sheet2.
Then sort it, and all text entries and numeric entries will be separated.
Then you can easily see and delete all the text entries.
You can then use Excel's built-in "Remove Duplicates" functionality to remove the numeric duplicates.

Then you should be left with just the unique numeric values!
Hello,
Yes I did that but was wondering that is there any vba code for it?
Cheers
 
Upvote 0
Hello,
Yes I did that but was wondering that is there any vba code for it?
Cheers
Yes, but that is the first you have mentioned using VBA to do this.

This code should do that:
VBA Code:
Sub MyCleanUpMacro()

    Dim lr As Long, r As Long
    
    Application.ScreenUpdating = False

'   Copy column A to sheet2
    Sheets("Sheet1").Columns("A:A").Copy Sheets("Sheet2").Range("A1")

'   Find last row with data
    Sheets("Sheet2").Activate
    lr = Cells(Rows.Count, "A").End(xlUp).Row

'   Sort column A on Sheet 2
    Range("A1:A" & lr).Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlNo, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    
'   Remove duplicates
    ActiveSheet.Range("A1:A" & lr).RemoveDuplicates Columns:=1, Header:=xlNo
    
'   Find new last row
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    
'   Remove all text entries from the bottom up
    For r = lr To 1 Step -1
'       Exit loop once you find a numeric entry
        If IsNumeric(Cells(r, "A")) Then
            Exit For
'       Otherwise delete row
        Else
            Rows(r).Delete
        End If
    Next r

    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Yes, but that is the first you have mentioned using VBA to do this.

This code should do that:
VBA Code:
Sub MyCleanUpMacro()

    Dim lr As Long, r As Long
   
    Application.ScreenUpdating = False

'   Copy column A to sheet2
    Sheets("Sheet1").Columns("A:A").Copy Sheets("Sheet2").Range("A1")

'   Find last row with data
    Sheets("Sheet2").Activate
    lr = Cells(Rows.Count, "A").End(xlUp).Row

'   Sort column A on Sheet 2
    Range("A1:A" & lr).Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlNo, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
   
'   Remove duplicates
    ActiveSheet.Range("A1:A" & lr).RemoveDuplicates Columns:=1, Header:=xlNo
   
'   Find new last row
    lr = Cells(Rows.Count, "A").End(xlUp).Row
   
'   Remove all text entries from the bottom up
    For r = lr To 1 Step -1
'       Exit loop once you find a numeric entry
        If IsNumeric(Cells(r, "A")) Then
            Exit For
'       Otherwise delete row
        Else
            Rows(r).Delete
        End If
    Next r

    Application.ScreenUpdating = True
   
End Sub
Thanks.
 
Upvote 0

Forum statistics

Threads
1,215,044
Messages
6,122,827
Members
449,096
Latest member
Erald

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