+ Reply to Thread
Results 1 to 12 of 12

Copy entire row where Duplicates are found in Column B

  1. #1
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Davenport, Iowa
    MS-Off Ver
    Excel 365
    Posts
    206

    Copy entire row where Duplicates are found in Column B

    Hi,

    I am looking for a script which can look at column B in a report - Identify the duplicates and copy the entire row (Or the range A:AZ) to a new workbook. I've tried to do this with a loop, however, with 50,000 rows it goes extremely slow and the script crashes my excel. Any help would be greatly appreciated...
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Copy entire row where Duplicates are found in Column B

    lol

    Copy the whole sheet to a new workbook

    Insert a formula in an empty column to count the number of times the entry in column B appears in column B

    If 1 then return 1 otherwise return ""

    Use the Select Special function to select all the Integers in column B ( In the Formula or as a constant )

    Then this line will delete all the entries that you do not want.

    Please Login or Register  to view this content.

    This is your code:

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 06-05-2020 at 12:14 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Davenport, Iowa
    MS-Off Ver
    Excel 365
    Posts
    206

    Re: Copy entire row where Duplicates are found in Column B

    mehmetcik,

    Thanks for the reply, however, I'm looking to keep this as a Run the macro to execute the task without any manual work being done...

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this demonstration ‼


    Before to look for a script just well think about what Excel offers to achieve your need 'cause here yes looping is not a great idea
    as any Excel beginner does not need a code and can operate manually in few seconds just using an Excel basics : an advanced filter !
    If really really he needs a code he can activate the Macro Recorder and operate manually in order to get his own code base …

    According to your attachment as a VBA beginner starter :

    PHP Code: 
    Sub Demo1()
             
    Application.ScreenUpdating False
             Workbooks
    .Add
        With Sheet1
    .UsedRange
            
    .Range("BB2").Formula "=COUNTIF(" & .Columns(2).Address ",B2)>1"
            
    .AdvancedFilter xlFilterCopy, .Range("BB1:BB2"), [A1]
            .
    Range("BB2").Clear
        End With
             Application
    .ScreenUpdating True
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Copy entire row where Duplicates are found in Column B

    Sorry

    I was explaining how the macro should work:

    Please Login or Register  to view this content.


    If you want to speed up the Macro.

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 06-05-2020 at 12:27 PM.

  6. #6
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Davenport, Iowa
    MS-Off Ver
    Excel 365
    Posts
    206

    Re: Copy entire row where Duplicates are found in Column B

    mehmetcik,

    Appreciate the quick response, the code you wrote works very well - One issue I ran into when running this on sample set is if there are no duplicates, the code bombs out. Is there a way to add a catch where if no duplicates are found the new workbook is not created?

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Copy entire row where Duplicates are found in Column B

    (removed …)
    Last edited by Marc L; 06-05-2020 at 12:31 PM.

  8. #8
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Copy entire row where Duplicates are found in Column B

    Try this version

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Davenport, Iowa
    MS-Off Ver
    Excel 365
    Posts
    206

    Re: Hi ! Try this demonstration ‼

    Marc,

    This works very well and does not error out when no duplicates were found... Is there any way to add a line of code where if no duplicates were found it wont create the workbook? Keep one thing in mind - I cannot modify the original document - its a master list of sorts and cannot be modified by adding or removing columns....

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Easy mod …


    After End With just insert this codeline : If IsEmpty([B2]) Then ActiveWorkbook.Close False

  11. #11
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Davenport, Iowa
    MS-Off Ver
    Excel 365
    Posts
    206

    Re: Easy mod …

    Marc,

    Thank you, that worked very well, much appreciated!

  12. #12
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Copy entire row where Duplicates are found in Column B

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 06-05-2020 at 02:19 PM.

+ 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] Copy Entire Row Insert Down below if Value found in Column P:P
    By tuongtu3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-22-2020, 02:08 AM
  2. [SOLVED] Search for value in row. if found, copy column formulas into found column range
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-23-2017, 10:42 AM
  3. automatically copy entire row to other sheet if ID is found.
    By Just64 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-23-2015, 01:46 AM
  4. How To Copy Entire Row When Red Cell Found
    By trevor2524 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-17-2013, 03:59 PM
  5. [SOLVED] Search a column for a value if found copy entire row and paste
    By awagenhurst in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2012, 03:48 PM
  6. copy entire row when entry was found
    By Irian in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-14-2011, 08:07 AM
  7. Index match to VBA copy the found entire row
    By Sjaaktrekhaak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-20-2009, 03:22 AM

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