VBA: Remove Duplicate Cells Based off of header

SteveOranjin

Board Regular
Joined
Dec 18, 2017
Messages
170
Can someone take a look at the VBA I wrote?

What I want this VBA to do is, remove all rows where there is a duplicate in a column with a certain header.

So I want it to work JUST like the remove duplicates, except I want it to run on the basis of a certain header.

sbRemoveDuplicatesSpecificWithHeaders() Range("Sheet1").RemoveDuplicates Columns:=Array(1), Header:= "SKU" xlYes End Sub

Anyone think they can help?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Will the header always be SKU, or do you want to specify the header?

EDIT
What row is the header in?
 
Last edited:
Upvote 0
In that case try
Code:
Sub RemoveDupes()
Dim Fnd As Range

With Sheets("Sheet1")
   Set Fnd = .Range("1:1").find("SKU", , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then .UsedRange.RemoveDuplicates Fnd.Column, xlYes
End With

End Sub
 
Upvote 0
In that case try
Code:
Sub RemoveDupes()
Dim Fnd As Range

With Sheets("Sheet1")
   Set Fnd = .Range("1:1").find("SKU", , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then .UsedRange.RemoveDuplicates Fnd.Column, xlYes
End With

End Sub


This is not removing the entire row. It's just removing the first five/six columns and then the rest of the stuff is moving up.

I was able to observe this because I created a duplicate and colored the row differently.

Steve
 
Upvote 0
How many columns do you have?
also what do you mean by

For the particular incident in question, I'd say there were probably at least 30 columns.

Just for simplicity sake though, I'm going to describe it as if there were 10 columns. You can easily extend the situation in question to more columns.

So lets say I created a duplicate. The Duplicate was in column "F". I colored all of the duplicate, so I would be able to see IF it was removed or not. I figured that there wouldn't be any sort of notification letting me know HOW much data was removed, so I wanted to make sure it was working.

Well when the duplicate was removed, the particular row in question was only removed up to say column G/H. So HIJK, or IJK still had colors on them.

That lead me to believe that only a PORTION of the data in question was actually removed. Not ALL of it.

Steve
 
Upvote 0
Do all the columns have the same number of rows after the macro has run, or if you started with (say) 10 rows & deleted 2, do cols IJK still have 10 rows?
Also do you have any merged cells?
 
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