Concatenate & Remove Duplicate

peelamedu_bulls

New Member
Joined
Nov 30, 2005
Messages
29
I have the following column values

Input
Account no Code
000005678 ABC
000005678 EDF
000001234 ABC
000001234 ABC

Desired Output
Account no Code
000005678 ABC
000005678 EDF
000001234 ABC

Criteria
Concatenate Column A and B (i.e Account No and Code)
If there are duplicates of this concatenated data, remove duplicates

I'm able to do this in VBA in a round about way, i.e create a column to concatenate two columns and then create one more column and use countif to determine if there are duplicates and then remove the duplicate. But it's long, and not elegant. Trying to avoid these calculation columns in the final output.

Is there a more elegant solution to this problem ?
 

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.
How about
Code:
Sub peelamedu2()
   With Range("A2", Range("A" & Rows.Count).End(xlUp))
      .Value = Evaluate("if({1}, " & .Address & " & " & .Offset(, 1).Address & ")")
      .Resize(, 2).RemoveDuplicates 1, xlNo
   End With
  [COLOR=#ff0000] Columns(2).Delete[/COLOR]
End Sub
Remove the line in red if you don't want to delete col B
 
Upvote 0
How about
Code:
Sub peelamedu2()
   With Range("A2", Range("A" & Rows.Count).End(xlUp))
      .Value = Evaluate("if({1}, " & .Address & " & " & .Offset(, 1).Address & ")")
      .Resize(, 2).RemoveDuplicates 1, xlNo
   End With
  [COLOR=#ff0000] Columns(2).Delete[/COLOR]
End Sub
Remove the line in red if you don't want to delete col B

Hi Fluff,

Do you know which version of excel first introduced the RemoveDuplicates functionality\Method ?

Regards.
 
Upvote 0
I think it was either 2007, or 2010.
 
Upvote 0
How about
Code:
Sub peelamedu2()
   With Range("A2", Range("A" & Rows.Count).End(xlUp))
      .Value = Evaluate("if({1}, " & .Address & " & " & .Offset(, 1).Address & ")")
      .Resize(, 2).RemoveDuplicates 1, xlNo
   End With
  [COLOR=#ff0000] Columns(2).Delete[/COLOR]
End Sub
Remove the line in red if you don't want to delete col B


Thank you.
However the output now is combined in one column, i.e Column A. I needed column A and B to be retained. Just the duplicates removed.

Desired output
Account No Code
000005678 ABC
000005678 EDF
000001234 ABC
 
Upvote 0
In that case how about
Code:
Sub peelamedu2()
   With Range("C2:C" & Range("A" & Rows.Count).End(xlUp).Row)
      .Value = Evaluate("if({1}, " & .Offset(, -2).Address & " & " & .Offset(, -1).Address & ")")
      .Offset(, -2).Resize(, 3).RemoveDuplicates 3, xlNo
   End With
   Columns(3).Delete
End Sub
This will put the concatenated values in col C & then delete it
 
Upvote 0
Is this how you whant
Code:
Sub do_it()
   With Range("A1", Range("A" & Rows.Count).End(xlUp)).Resize(, 2)
     .RemoveDuplicates Columns:=Array(1, 2), Header:=xlYes
   End With
  End Sub
 
Upvote 0
@mohadin
Using RemoveDuplicates on multiple columns like that is unreliable & I would recommend against using.
 
Upvote 0

Forum statistics

Threads
1,223,883
Messages
6,175,168
Members
452,615
Latest member
bogeys2birdies

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