Results 1 to 3 of 3

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

Threaded View

  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

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