delete duplicate rows based on two column names

boiboi

New Member
Joined
Apr 9, 2019
Messages
19
Hi,

Can anyone help with below? My code is running for around 5 minutes or more with data of only 10 records in the worksheet.

Dim nameCol As Range
Dim aCell As Range
Dim Cell As Range
Dim Cel As Range, N&
N = 0


Set nameCol = .Range("A1:AU1").Find("apple")
Set aCell = .Range("A1:AU1").Find("orange")

Application.Union(nameCol, aCell).EntireColumn.Select

For Each Cell In Selection
If Cell <> Empty Then
For Each Cel In Selection
If Cel <> Empty And _
Cel.Value = Cell.Value And _
Cel.Address <> Cell.Address Then
Cel.EntireRow.Delete
N = N + 1
End If
Next Cel
End If
Next


Much appreciated in advance.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
How about
Code:
Sub boiboi()
   Dim Fnd1 As Range, Fnd2 As Range
   
   Set Fnd1 = Range("1:1").Find("apple", , , xlWhole, , , False, , False)
   Set Fnd2 = Range("1:1").Find("orange", , , xlWhole, , , False, , False)
   If Fnd1 Is Nothing Then Exit Sub
   If Fnd2 Is Nothing Then Exit Sub
   ActiveSheet.UsedRange.RemoveDuplicates Array(Fnd1.Column, Fnd2.Column), xlYes
End Sub
 
Upvote 0
Try
Code:
   With TargetWS
      Set Fnd1a = .Range("1:1").Find("apple", , , xlWhole, , , False, , False)
      Set Fnd2a = .Range("1:1").Find("orange", , , xlWhole, , , False, , False)
      If Fnd1a Is Nothing Then Exit Sub
      If Fnd2a Is Nothing Then Exit Sub
      .UsedRange.RemoveDuplicates Array(Fnd1a.Column, Fnd2a.Column), xlYes
    End With
 
Upvote 0
hi fluff,

if i wanted to highlight the duplicate rows, instead of removing them, is there any way to go about it?
 
Upvote 0
That's what the code in post#8 does.
 
Upvote 0
Using Sheet1 from the file supplied in post#15 I get


Excel 2013/2016
ABCDEFGHI
1kiwigrapemangoappledurianpineappletomatoorangecoconut
2abcdefabc1abcaabc
3abcdefabc2abcbabc
4abcdefabc3abcaabc
5abcdefabc4abcbabc
6abcdefabc5abcaabc
7abcdefabc5abcbabc
8abcdefabc5abc@abc
9abcdefabc5abc@abc
10abcdefabc5abc@abc
11abcdefabc5abc@abc
12
13abcdefabc13abcbabc
14abcdefabc14abcbabc
15abcdefabc14abc@abc
16abcdefabc15abc@abc
17abcdefabc18abcbabc
18abcdefabc19abcbabc
19abcdefabc20abcaabc
20abcdefabc22abcbabc
21abcdefabc5abc@abc
22abcdefabc5abc@abc
Sheet1


in what way is that wrong?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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