+ Reply to Thread
Results 1 to 2 of 2

How to remove duplicates with a criteria

Hybrid View

  1. #1
    Registered User
    Join Date
    07-31-2014
    Location
    Singapore
    MS-Off Ver
    Excel 2007
    Posts
    17

    How to remove duplicates with a criteria

    Attached is the file for reference.

    I would like to FIRST, identify duplicated columns (in this case, they are column C and D, with "FY 2012" as its header). Those that do NOT have duplicate, leave them untouch (in this case, it's column B).

    SECOND, for the columns that have duplicated headers, I would want to delete the column with the second header "original", but leave the data "restated" untouched
    .
    Essentially I want to write up a code that delete column D, but leaves columns A,B and C untouched.

    How should I do that?

    Test Sample 3.xlsm

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: How to remove duplicates with a criteria

    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    Sub RemoveDuplicateColumn()
    Dim iCl As Integer, rFound As Range
    
    iCl = Cells(1, Columns.Count).End(xlToLeft).Column
    
    Application.ScreenUpdating = False
    
    Rows("1:1").Insert
    
    With Range("B1", Cells(1, iCl))
        .Formula = "=IF(COUNTIF(R2C1:R[1]C,R[1]C)>1,""Delete"",""Retain"")"
        .Value = .Value
        Set rFound = .Find("Delete")
        Do While Not rFound Is Nothing
            rFound.EntireColumn.Delete
            Set rFound = .Find("Delete")
        Loop
    End With
    
    Rows("1:1").Delete
    
    Application.ScreenUpdating = True
    
    End Sub
    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

+ 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. Macro to remove duplicates (If duplicate meets all three criteria)
    By adw223 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-01-2013, 05:46 PM
  2. Remove Duplicates with Criteria
    By cowtipper in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-08-2013, 05:40 PM
  3. [SOLVED] Remove duplicates inside the cells (with criteria)
    By julia81 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-11-2012, 12:22 PM
  4. Remove duplicates based on criteria
    By keswickjeff in forum Excel General
    Replies: 2
    Last Post: 07-14-2011, 12:15 PM
  5. Remove duplicates for certain criteria(s) behind the scene and paste sum in cell.
    By Cedicon in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-20-2011, 03:26 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