+ Reply to Thread
Results 1 to 11 of 11

how to copy duplicate cells to a second sheet?

Hybrid View

AccountingJ how to copy duplicate cells... 08-18-2020, 11:49 AM
Sintek Re: how to copy duplicate... 08-18-2020, 11:52 AM
AccountingJ Re: how to copy duplicate... 08-18-2020, 11:56 AM
Sintek Re: how to copy duplicate... 08-18-2020, 12:02 PM
AccountingJ Re: how to copy duplicate... 08-18-2020, 12:08 PM
Sintek Re: how to copy duplicate... 08-18-2020, 12:12 PM
AccountingJ Re: how to copy duplicate... 08-18-2020, 01:34 PM
Sintek Re: how to copy duplicate... 08-18-2020, 02:00 PM
AccountingJ Re: how to copy duplicate... 08-19-2020, 01:58 PM
Sintek Re: how to copy duplicate... 08-19-2020, 03:27 PM
AccountingJ Re: how to copy duplicate... 08-19-2020, 03:40 PM
  1. #1
    Forum Contributor
    Join Date
    09-19-2016
    Location
    Alaska
    MS-Off Ver
    MS 2010, 2013, 2016
    Posts
    272

    how to copy duplicate cells to a second sheet?

    Hi everyone, I have sheets that sometimes has up to 5k rows. Column E is known to sometimes have duplicates so I have the macro below to look and copy those duplicate cells to sheet2. When I run it I get "No cells were found." and i'm not sure why.

    Option Explicit
    
    Sub FilterAndCopy()
    
    Dim wstSource As Worksheet, _
        wstOutput As Worksheet
    Dim rngMyData As Range, _
        helperRng As Range
    
    Set wstSource = Worksheets("Sheet1")
    Set wstOutput = Worksheets("Sheet2")
    
    Application.ScreenUpdating = False
    
    With wstSource
        Set rngMyData = .Range("A1:R" & .Range("E" & .Rows.Count).End(xlUp).Row)
    End With
    Set helperRng = rngMyData.Offset(, rngMyData.Columns.Count + 1).Resize(, 1)
    
    With helperRng
        .FormulaR1C1 = "=if(countif(C1,RC1)>1,"""",1)"
        .Value = .Value
        .SpecialCells(xlCellTypeBlanks).EntireRow.Copy Destination:=wstOutput.Cells(1, 1)
        .ClearContents
    End With
    
    Application.ScreenUpdating = True
    
    End Sub
    Attached Files Attached Files
    Last edited by AccountingJ; 08-19-2020 at 01:57 PM.

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

    Re: how to copy duplicate cells to a second sheet?

    That's because there are no blanks...
    Last edited by Sintek; 08-18-2020 at 01:20 PM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Contributor
    Join Date
    09-19-2016
    Location
    Alaska
    MS-Off Ver
    MS 2010, 2013, 2016
    Posts
    272

    Re: how to copy duplicate cells to a second sheet?

    sheet1 has values in its cells.

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

    Re: how to copy duplicate cells to a second sheet?

    Yes, but you are trying to copy rows which have blank cells in Col T and there aren't any...
    Put an if statement to check blankcell count first or make use of On error resume Next | On error goto 0

  5. #5
    Forum Contributor
    Join Date
    09-19-2016
    Location
    Alaska
    MS-Off Ver
    MS 2010, 2013, 2016
    Posts
    272

    Re: how to copy duplicate cells to a second sheet?

    Where are you getting col T? it should be E.

  6. #6
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

    Re: how to copy duplicate cells to a second sheet?

    Your formula is placed in Col T (Helper Range) and then you are checking for blanks in thiscolumn to copy over to other sheet?
    If all rows are 1 then there are no duplicates...If there are blanks in Col T then there are duplicates to copy over...
    If Evaluate("=COUNTBLANK(" & .Address & ")") > 0 Then .SpecialCells(xlCellTypeBlanks).EntireRow.Copy Destination:=wstOutput.Cells(1, 1)

    Put a duplicate in Col A and run your code...It will not error because it will find 2 blank cells in Col T
    Which is the actual Col to check for Dups...Your formula is using col A
    Last edited by Sintek; 08-18-2020 at 12:38 PM.

  7. #7
    Forum Contributor
    Join Date
    09-19-2016
    Location
    Alaska
    MS-Off Ver
    MS 2010, 2013, 2016
    Posts
    272

    Re: how to copy duplicate cells to a second sheet?

    got it, thank you, I changed it to this:

    .SpecialCells(xlCellTypeBlanks).EntireRow.Copy Destination:=wstOutput.Cells(5, 1)
    it works, except it does not copy to the first available row (row 2 is the first available one).

  8. #8
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

    Re: how to copy duplicate cells to a second sheet?

    Not sure what got it means...Is the sample data and setup still same?...First row is Header?

    See upload...It will copy highlighted rows...
    Attached Files Attached Files
    Last edited by Sintek; 08-18-2020 at 02:04 PM.

  9. #9
    Forum Contributor
    Join Date
    09-19-2016
    Location
    Alaska
    MS-Off Ver
    MS 2010, 2013, 2016
    Posts
    272

    Re: how to copy duplicate cells to a second sheet?

    Yes same set-up, first row is header but I managed to make the change in your macro so it can start copying on the second row of sheet2. If I was even a fraction as smart as you are when it comes to macros, then my life would be simpler.

    Thanks again, i really appreciate it.

  10. #10
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,964

    Re: how to copy duplicate cells to a second sheet?

    can start copying on the second row of sheet2
    Oh man ... now I get it...you meant copy to...not copy from...

    Your code was copying to first row...
    wstOutput.Cells(1, 1)

  11. #11
    Forum Contributor
    Join Date
    09-19-2016
    Location
    Alaska
    MS-Off Ver
    MS 2010, 2013, 2016
    Posts
    272

    Re: how to copy duplicate cells to a second sheet?

    No worries, I didn't explain correctly the first time. Thanks Sintek.

+ 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] Find duplicate cells, copy and paste it into new sheet (plus sum of values)
    By josemtzdlr in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-13-2019, 12:49 PM
  2. [SOLVED] VBA - Macro issue copy/paste line other sheet + duplicate current sheet
    By vcourbiere in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-17-2014, 12:06 PM
  3. Macro Multi Sheet Duplicate Copy to New Sheet
    By Digital_Warrior in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-01-2013, 02:54 PM
  4. Insert a row, duplicate a sheet and copy cells to master sheet?
    By Dagoom in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-25-2013, 01:26 AM
  5. Need a Macro that will duplicate a spreadsheet, then copy data from cells into new sheet
    By missmea2005 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-29-2012, 02:06 PM
  6. [SOLVED] Find Duplicate name in 3 sheets, copy certain cells to a spefic location in 4th sheet
    By Jim9_1100 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 07-16-2012, 06:29 PM
  7. Search column a for duplicate data and copy entire row to duplicate sheet
    By crazyAMP in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-20-2012, 08:21 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