I've got to compare two columns of numbers and see if they match, I only want to keep the unique numbers (ie. existing in only one of the two columns). I'm using notepad++ and excel. How do i do this? Please help! I already tried some excel tricks, but those are usually too slow or inflexibleI want to compare two columns of numbers and leave only the unique numbers (only existing in one column). How?
You can do it with a macro like this. It will clear all duplicated numbers and sort each column ascending.
If your columns are not A and B, you will need to modify the macro thusly:
Change all ';A'; to your first column letter, i.e. ';D';
Change all ';B'; to your second column letter, i.e. ';E';
Change all ';A1:B'; to your 1st and 2nd column letters, i.e ';D1:E';
Change the ';A:A'; to your 1st column letter, i. e. ';D:D';
Change the ';B:B'; to your 2nd column letter, i.e. ';E:E';
Change the ';A1'; to your 1st column letter, i.e. ';D1';
Change the ';B1'; to your 2nd column letter, i.e ';E1';
Or, simply use columns A and B...
Copy this macro, modified if necessary, to the clipboard:
-------
Sub Unique_Columns()
Dim LastRow, i
LastRow = Range(';A'; %26amp; ActiveSheet.Rows.Count). _
End(xlUp).Row
For i = 1 To LastRow
If Application.CountIf(Range(';A1:B'; %26amp; _
LastRow), Cells(i, ';A';)) %26gt; 1 Then
Cells(i, ';A';).Value = ';';
End If
If Application.CountIf(Range(';A1:B'; %26amp; _
LastRow), Cells(i, ';B';)) %26gt; 1 Then
Cells(i, ';B';).Value = ';';
End If
Next
Columns(';A:A';).Select
Selection.Sort Key1:=Range(';A1';), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Columns(';B:B';).Select
Selection.Sort Key1:=Range(';B1';), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range(';A1';).Select
End Sub
----------
Select the appropriate worksheet and right click on the sheet tab.
Select 'View Code'
Paste the macro into the module area to the right.
Close back to Excel.
Go to Tools %26gt; Macro %26gt; Macros
Highlight this macro, if not already highlighted.
Click 'Options'
Select a letter to be used as a keyboard shortcut.
Close back to Excel.
Press Ctrl + your letter to run the macro.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment