+ Reply to Thread
Results 1 to 3 of 3

Unable to Paste Duplicate values in a new excel sheet within the same excel workbook

  1. #1
    Registered User
    Join Date
    06-23-2020
    Location
    India
    MS-Off Ver
    2010
    Posts
    25

    Unable to Paste Duplicate values in a new excel sheet within the same excel workbook

    Hello,

    Greetings!

    I have been working on a VBA code where there are more than 33,000 rows of data. I have been trying to find the duplicate entries, copy and paste those duplicates in a new defined sheet "Duplicates" and then delete them from raw sheet "Raw Data". My code is running fine when run manually in the module but when I click on a button to run this code, nothing gets pasted in "Duplicates" sheet. The duplicate data gets deleted but it doesn't paste anything in the "Duplicates" sheet. Any leads will be much appreciated. Please note: since my data is huge, that is why I have used a loop here. Attached is just a dummy book.

    I have attached a sample dummy report. Here is the code that I have drafted:

    Set main_wbk = Workbooks("Book1.xlsx")
    Set main_sht = main_wbk.Sheets("Raw Data")

    main_sht.Activate 'find duplicates in column A, colour as yellow

    For iCntr = 1 To lastRow2
    If Cells(iCntr, 1) <> "" Then
    matchFoundIndex = WorksheetFunction.Match(Cells(iCntr, 1), range("A1:A" & lastRow2), 0)
    If iCntr <> matchFoundIndex Then
    Cells(iCntr, 2).Interior.Color = vbYellow
    End If
    End If
    Next

    With main_sht 'copy yellow colour in column B and copy and paste in duplicate sheet

    main_sht.AutoFilterMode = False
    main_sht.range("a1:bp1").AutoFilter Field:=2, Criteria1:=RGB(255, 255, 0), Operator:=xlFilterCellColor
    main_sht.range("a1:bp" & lastRow).SpecialCells(xlCellTypeVisible).Copy

    End With

    main_wbk.Worksheets("Duplicates").range("a1").PasteSpecial

    main_sht.range("a2:bp" & lastRow2).SpecialCells(xlCellTypeVisible).EntireRow.Delete 'remove duplicates
    Attached Files Attached Files

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: Unable to Paste Duplicate values in a new excel sheet within the same excel workbook

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    Best Regards,

    Kaper

  3. #3
    Valued Forum Contributor
    Join Date
    11-04-2018
    Location
    Denpasar
    MS-Off Ver
    Excel 2010
    Posts
    777

    Re: Unable to Paste Duplicate values in a new excel sheet within the same excel workbook

    I think you just need to add this line in the beginning of the sub :
    Please Login or Register  to view this content.
    And change the lastRow in this line :
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

+ 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. Copy an excel sheet and paste into another workbook
    By ikshanu in forum Excel General
    Replies: 2
    Last Post: 09-25-2018, 06:24 PM
  2. Duplicate Values In a column of an excel sheet
    By yatindatta in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-28-2018, 03:16 AM
  3. Excel VBA copy and paste sheet to open workbook
    By Hoover5896 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-22-2017, 02:25 PM
  4. unable to paste data in the same work sheet in excel 2007
    By fhadzafar in forum Excel General
    Replies: 3
    Last Post: 05-29-2015, 02:18 PM
  5. EXCEL: Restrict User To Paste Special Values Only In Particular WorkBook
    By gaikwad.mm@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-14-2013, 03:34 AM
  6. [SOLVED] Unable to copy data from source excel to destination excel workbook
    By Lui23 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-21-2012, 07:22 AM
  7. how to copy excel sheet from one workbook and paste into another workbook, save it ?
    By dearnemo385 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-17-2012, 08:27 AM

Tags for this Thread

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