+ Reply to Thread
Results 1 to 2 of 2

Deleting duplicates based on row with largest amount of filled cells.

  1. #1
    Registered User
    Join Date
    10-19-2022
    Location
    Norway
    MS-Off Ver
    365
    Posts
    3

    Deleting duplicates based on row with largest amount of filled cells.

    Hi,

    I have a macro which adds data from an external rapport onto a local excel-file.
    This invariably leads to duplicates (based on ID).

    As the data is updated from both sides, I want to make the macro which imports the rapport also be able to remove duplicates based on which rows has the most amount of cells filled in.

    In short, from the example. I am struggling to create a macro that deletes all duplicates of dr. Pepper and only leaves the row in which the most data-points has been filled in (ie. row 5).

    I have tried possibly creating a function that counts the filled cells and marks the top one, but I can't really find a way to make it work.

    Any help or hints are greatly appreciated
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Deleting duplicates based on row with largest amount of filled cells.

    Hello. You can try with:

    PHP Code: 
    Sub Macro25()
    Dim R%
    Application.ScreenUpdating False
    With Sheets
    ("Data")
      
    With .Cells(1).CurrentRegion
        R 
    = .Columns.Count: .Cut .Cells(12): .Cells(1,0) = "Tttt"
      
    End With
      With 
    .Cells(1).CurrentRegion
        
    .Columns(1) = "=CountA(" & .Cells(12).Resize(, R).Address(00) & ")"
        
    .Columns(1) = .Columns(1).Value: .Cells(1) = "Tttt"
        
    .Sort .Cells(12), 1key2:=.Cells(1), order2:=2Header:=xlYes
        
    .RemoveDuplicates Columns:=2Header:=xlYes
        
    .Columns(1).Delete xlToLeft
      End With
    End With
    End Sub 
    Last edited by beyond Excel; 11-21-2022 at 02:18 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] Deleting random cells to the left if filled with a certain background colour
    By coach.32 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-09-2017, 05:08 PM
  2. [SOLVED] Help choosing largest or 2nd largest amount of consecutive 0's if a criteria is met
    By jonodillieono in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-06-2016, 09:52 AM
  3. Duplicates with Cells that are Filled
    By trevor2524 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-05-2014, 12:30 PM
  4. [SOLVED] How to merge empty with filled cells without deleting?
    By kingi in forum Excel General
    Replies: 2
    Last Post: 09-27-2013, 03:20 AM
  5. [SOLVED] Formula to extract top largest to smallest amount based on 3 criterias
    By aurisab in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-26-2013, 08:05 AM
  6. Returning Max value, 2nd largest, 3rd largest, etc without duplicates
    By ARayburn in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 05-21-2013, 11:49 AM
  7. Autofit Columns based on largest amount of characters
    By dagindi in forum Excel General
    Replies: 2
    Last Post: 01-18-2012, 06:28 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