If duplicate in a cell then keep 1st row and move remaining row to new sheet/ excel

goodstudent

New Member
Joined
Dec 8, 2023
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hello to all from a newbie on the forum,

I know how to use excel but I don't know how to use VBA.

It would be gracious of you all if you could help me please. I have the following table:

1702029521939.png


I have the above excel sheet.

I would like to find duplicates in PRODUCT column. Then for all the duplicate columns only, I would like to keep the first appearance, and move all following duplicate rows to a new sheet/ excel file and in the main sheet move the removed (now empty) rows up. Thanks in advance!
 

Attachments

  • 1702029439729.png
    1702029439729.png
    104.1 KB · Views: 21

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.
Welcome to the Board!

Might I suggest an alternative approach that is very easy does not require any VBA?

If you add a "helper" column to the end of the data that counts the occurrence of each entry, we will be able to do this with no VBA.
So, the formula in E2 would look like this and be copied down for all rows:
Excel Formula:
=COUNTIF($B$2:$B2,$B2)

So, on this sample data I created on "Sheet1", it would look like this:
1702040570565.png


Then, to only show the first occurrence of each Product, just filter column E to only return rows where the value is 1, i.e.
1702040636966.png


And then on Sheet2, we can use the new FILTER function to return all the other rows by placing this formula in cell A2:
Excel Formula:
=FILTER(Sheet1!A2:E10,Sheet1!E2:E10>1)

which will return:
1702040701280.png


That seems to separate the data the way you want.
Does that work for you?
 
Upvote 1
Hello Joe4,

Thanks for the welcome and your kind response.
Ok, I will work with your method and see if it will be suitable for me in the long run.

For now, I am getting error just I started with your suggestion. See below screenshot. What is wrong with the formula, please? I copy+pasted the formula you wrote.

1702047910629.png
 
Upvote 0
Perhaps your version of Excel uses semi-colons instead of commas to separate formula arguments?
If so, change the formula to:
Excel Formula:
=COUNTIF($B$2:$B2;$B2)
 
Upvote 1
Solution
Hello, Thanks for the response!

yes with semi-colon ( ; ) it worked. Now, instead of moving to the next step...I can also sort by COUNT and cut paste the columns (from count 2 onwards) to another sheet/ excel as soon as the count arrives to 2 :)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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