+ Reply to Thread
Results 1 to 19 of 19

Create New Worksheet based on duplicates in Multiple worksheets

  1. #1
    Registered User
    Join Date
    04-10-2019
    Location
    California
    MS-Off Ver
    16.0.11425.20200
    Posts
    14

    Create New Worksheet based on duplicates in Multiple worksheets

    Hello everyone,

    So like the titles says, I'm trying to create a new worksheet based on duplicates in multiple worksheets. I am halfway there already with the following code; however, it is only looking at Sheet1 and Sheet2. What I am trying to do, is have multiple worksheets, maybe up to 15 different worksheets, to locate duplicate ROWS and transfer those ROWS to a new worksheet. The following code allows me to search for duplicates in sheet1 and sheet2, but I am unable to figure out how to allow VBA to search thru multiple worksheets. One day I might have 8, another day I might have 15, but I would like to figure out how to adjust this code so it won't matter the amount of worksheets I have, it will search thru them all, locate the duplicate ROWS and paste them or place them into a new RENAMED worksheets. See VBA code below on how I started out already. Can anyone inform me on what I can add or adjust to create my desired results?

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,261

    Re: Create New Worksheet based on duplicates in Multiple worksheets

    Welcome to the forum ...

    Ad rem ...
    Quote Originally Posted by a1cswiz View Post
    ... to locate duplicate ROWS and transfer those ROWS to a new worksheet ...
    Rows or cells in rows ?
    In your code you have:
    Please Login or Register  to view this content.
    , and this is a single cell (ar(i, 1)), not a row.
    Does it mean duplicates of cells, but "copy/move" (transfer ?) entire rows from the current range ?
    Could you attach a brief example of the appearance of the data ?

  3. #3
    Registered User
    Join Date
    04-10-2019
    Location
    California
    MS-Off Ver
    16.0.11425.20200
    Posts
    14
    Hi porucha vevrku,

    Sure, I can do that. I’m currently away from my computer but in the meantime I’ll explain again. The code matches one cell, that is correct. Each worksheet has the same headings, but the information under the headings could be different.

    For example: one worksheet, the row has “John” “Smith” “Fat” “5’6” inputted into A2; B2; C2;D2 respectively. Labeled underneath their respective headings. In this worksheet, there could be 100+ names in the rows. Now in Sheet2, there is another list of names with the same headings and so on and so forth. I want to compare all the sheets, locate the duplicated rows, and create entire new sheet with all those duplicate rows. So if John, Smith, Fat and 5’6 were located in all the sheets, then that should show up into the newly created worksheet. Does that explain a little better? The code I have only compares one cell and then makes a new sheet based off of sheet1 and sheet2. But I want it to look at sheet3, 4,5 or how many sheets I put in it. Does this explain a little better?
    Last edited by jeffreybrown; 04-13-2019 at 12:57 PM. Reason: Removed full quote!

  4. #4
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,261

    Re: Create New Worksheet based on duplicates in Multiple worksheets

    Quote Originally Posted by a1cswiz View Post
    ... I want to compare all the sheets ... So if John ... were located in all the sheets ... into the newly created worksheet ...
    1. For example: you have 15 worksheets - what if the duplicates are only in 3 sheets ?
    2. What about the repetition (duplicated rows) within a given one sheet ? Do they exist at the sheet level or only between sheets ? If they exist, will they be subject to transfer ?

  5. #5
    Registered User
    Join Date
    04-10-2019
    Location
    California
    MS-Off Ver
    16.0.11425.20200
    Posts
    14

    Re: Create New Worksheet based on duplicates in Multiple worksheets

    1. If there are 15 sheets, then the code should trigger if all duplicates are in all 15 sheets. If they exist in only 3, then it won't trigger.

    2. There will not be duplicated rows within the same sheet.

    Good questions, I hope I explained well enough. I got it half working with my code, but again, only with two sheets, not more than that. I just can't figure out how to add more sheets and allow the code to look at those also.

  6. #6
    Forum Contributor
    Join Date
    03-22-2017
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: Create New Worksheet based on duplicates in Multiple worksheets

    As there will not be duplicated rows within the same sheet,

    you may try:
    1. merge all sheets.
    2. Countif to identify duplicate
    3. Remove if < Number of Sheet (ThisWorkbook.Worksheets.Count)
    4. Remove the duplication.
    Last edited by BoredWorker; 04-11-2019 at 09:54 PM.

  7. #7
    Registered User
    Join Date
    04-10-2019
    Location
    California
    MS-Off Ver
    16.0.11425.20200
    Posts
    14
    Hi BoredWorker,

    But where in the code would I put that? Would you be able to copy the entire code I need to this thread?
    Last edited by jeffreybrown; 04-13-2019 at 12:57 PM.

  8. #8
    Forum Contributor
    Join Date
    03-22-2017
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: Create New Worksheet based on duplicates in Multiple worksheets

    i mean is to create a new code...

    edit the red one to the unique id column. (i.e can ignore the sheet, it just need column number.)
    it only limited table only start will row1 or change the Blue one to the header cells (i.e. any location of the table header)
    Please Login or Register  to view this content.
    Last edited by BoredWorker; 04-12-2019 at 02:11 AM.

  9. #9
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,261

    Re: Create New Worksheet based on duplicates in Multiple worksheets

    Quote Originally Posted by BoredWorker View Post
    1. merge all sheets.
    2. Countif to identify duplicate
    3. Remove if < Number of Sheet (ThisWorkbook.Worksheets.Count)
    4. Remove the duplication.
    Quote Originally Posted by BoredWorker View Post
    i mean is to create a new code...
    Good idea, but:

    1. You did not take it into account:

    Quote Originally Posted by a1cswiz View Post
    ... the row has “John” “Smith” “Fat” “5’6” inputted into A2; B2; C2;D2 respectively ...
    ... So if John, Smith, Fat and 5’6 were located in all the sheets, then that should ...
    You take into account in your code, only one cell from one column ('A'), not many cells from different columns.

    “John Smith Fat 5’6” <> “John Smith Fatt 5’7”

    2. Not everyone has an excel version above 2k3 yet, so you can not always use the "Delete duplicates" method.
    Last edited by mjr veverka; 04-12-2019 at 08:38 PM.

  10. #10
    Registered User
    Join Date
    04-10-2019
    Location
    California
    MS-Off Ver
    16.0.11425.20200
    Posts
    14

    Re: Create New Worksheet based on duplicates in Multiple worksheets

    BoredWorker,

    Okay, I just plugged the Code in and ran it and it is not working how I want it too. It is not picking up on the duplicates. I'll lay out an example below:

    Sheet1
    ADDRESS LAST NAME FIRST NAME ZIP CODE
    123 Chester St Smith John 45125
    563 Weed Ln Jones Ronald 17845

    Sheet2
    ADDRESS LAST NAME FIRST NAME ZIP CODE
    4444 Hell Rd Heck Sarah 17845
    563 Weed Ln Jones Ronald 17845

    "Report Sheet" (Created after running the macro")
    ADDRESS LAST NAME FIRST NAME ZIP CODE
    563 Weed Ln Jones Ronald 17845
    Last edited by jeffreybrown; 04-13-2019 at 12:52 PM. Reason: Removed full quote!

  11. #11
    Registered User
    Join Date
    04-10-2019
    Location
    California
    MS-Off Ver
    16.0.11425.20200
    Posts
    14

    Re: Create New Worksheet based on duplicates in Multiple worksheets

    Hi porucha vevrku,

    I would be satisfied if it would just pick up on one column; however, it is not even doing that with the code provided above
    Last edited by jeffreybrown; 04-13-2019 at 12:58 PM.

  12. #12
    Registered User
    Join Date
    04-10-2019
    Location
    California
    MS-Off Ver
    16.0.11425.20200
    Posts
    14

    Re: Create New Worksheet based on duplicates in Multiple worksheets

    Hi porucha vevrku,

    If it would just search for the words John in Column A, located the duplicates and then transfer for the entire Row that "john" was on, would be exactly what I am trying to do
    Last edited by jeffreybrown; 04-13-2019 at 12:58 PM. Reason: Removed full quote!

  13. #13
    Registered User
    Join Date
    04-10-2019
    Location
    California
    MS-Off Ver
    16.0.11425.20200
    Posts
    14

    Re: Create New Worksheet based on duplicates in Multiple worksheets

    Okay, I believe I know what the problem was. IT WORKS; however, the sheets that were given to me, and the way the data was laid out was different. So basically, there is an empty row between each row of data. Row1 has the heading, Row 2 begins the first row of data, Row3 is blank, Row4 is the next set of data and so on and so forth. I went in and deleted all the empty rows and then it worked. I will run another macro that formats and deletes all empty rows before running this macro code. I'll see what I can come up with.

  14. #14
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,261

    Re: Create New Worksheet based on duplicates in Multiple worksheets

    Solution according to the idea of ​​BoredWorker (no dictionary, only one-time with an array variable, the rest of the commands are excel typically). It should also work in older versions of Excel, try:
    Please Login or Register  to view this content.
    Attached Files Attached Files

  15. #15
    Registered User
    Join Date
    04-10-2019
    Location
    California
    MS-Off Ver
    16.0.11425.20200
    Posts
    14

    Re: Create New Worksheet based on duplicates in Multiple worksheets

    Solved: With all of your great help, I finally have what I was looking for. You guys and this forum has been a tremendous help. Below is the code and it checks all out.

    Please Login or Register  to view this content.
    Last edited by jeffreybrown; 04-13-2019 at 12:52 PM. Reason: Removed full quote!

  16. #16
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: Create New Worksheet based on duplicates in Multiple worksheets

    Hi a1cswiz,

    Please do not quote full posts as this just causes thread clutter.
    HTH
    Regards, Jeff

  17. #17
    Registered User
    Join Date
    04-10-2019
    Location
    California
    MS-Off Ver
    16.0.11425.20200
    Posts
    14

    Re: Create New Worksheet based on duplicates in Multiple worksheets

    you got it

  18. #18
    Registered User
    Join Date
    04-10-2019
    Location
    California
    MS-Off Ver
    16.0.11425.20200
    Posts
    14

    Re: Create New Worksheet based on duplicates in Multiple worksheets

    Instead of looking at all sheets, what if I wanted to just see out of the 15 sheets if there are at least two duplicates, how would I write the code?

  19. #19
    Forum Contributor
    Join Date
    03-22-2017
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: Create New Worksheet based on duplicates in Multiple worksheets

    it just need to change Red (WK_Count) to any amount of duplication you need, it based on the below rule.

    in your case change then condition to >2

    3. Remove if (the number of duplicates) <> Number of Sheet (ThisWorkbook.Worksheets.Count)

    Please Login or Register  to view this content.
    Hope you can learn every time you visit here.

    If you still confuse on how it work, kindly ask or go to
    i) Formula - Formula (Ribbon) > Formula Auditing (Section) > Evaluate Formula > Evaluate; or
    ii) VBA/Code - Click F8 to see how it work step by step.

    It it take care of your question, Please:
    Mark tread as [Solved] [Thread Tools->Mark thread as Solved]
    ;and
    Click *Add Reputation to thank anyone solved your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Remove duplicates between worksheets based on multiple rows
    By Pango in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-01-2016, 09:11 PM
  2. Replies: 14
    Last Post: 01-28-2014, 01:45 PM
  3. Replies: 3
    Last Post: 08-26-2013, 03:31 PM
  4. [SOLVED] Find duplicates in multiple worksheets and consolidate based on unique id
    By desibabuji in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-14-2013, 04:09 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1