+ Reply to Thread
Results 1 to 3 of 3

Merge duplicate rows, sum values of columns and choose latest date for duplicates with VBA

  1. #1
    Registered User
    Join Date
    02-09-2022
    Location
    Ogden, Utah
    MS-Off Ver
    Office 365
    Posts
    26

    Merge duplicate rows, sum values of columns and choose latest date for duplicates with VBA

    Hello,

    My mind is about to explode trying to figure out how to do this. I have a sheet of data with columns A through AD, I want to find duplicates based off of column A. If a duplicate is found columns G through AD need to be summed in each respective column, I also need to keep all columns in tact. If a duplicate is found I need to look at column F and compare the dates associated with each duplicate to choose the date that is in the future the furthest and use all the column information with that date. I need to have this pasted into a separate sheet.

    Also the amount of rows the data set has will changed so I need to VBA code to be dynamic to accommodate changes automatically.

    I tried to attached a before and after excel sample but not sure if it worked so I took a snip of that file to see if that will help illustrate what I mean. Hopefully I'm making sense.

    Capture.GIF
    Attached Files Attached Files
    Last edited by VBAhelp1; 02-10-2022 at 11:53 AM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Merge duplicate rows, sum values of columns and choose latest date for duplicates with

    Output to Sheet2
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-09-2022
    Location
    Ogden, Utah
    MS-Off Ver
    Office 365
    Posts
    26

    Re: Merge duplicate rows, sum values of columns and choose latest date for duplicates with

    Thank you Jindon, That worked wonderfully. I had change one small thing for the date comparison section, but worked amazing afterwards.

    Sub test()
    Dim a, i As Long, ii As Long
    a = Sheets("sheet1").Cells(1).CurrentRegion.Value
    With CreateObject("Scripting.Dictionary")
    For i = 2 To UBound(a, 1)
    If Not .exists(a(i, 1)) Then
    .Item(a(i, 1)) = .Count + 2
    For ii = 1 To UBound(a, 2)
    a(.Count + 1, ii) = a(i, ii)
    Next
    Else
    If a(i, 6) >= a(.Item(a(i, 1)), 6) Then
    For ii = 1 To 6
    a(.Item(a(i, 1)), ii) = a(i, ii)
    Next
    End If
    For ii = 7 To UBound(a, 2)
    a(.Item(a(i, 1)), ii) = a(.Item(a(i, 1)), ii) + a(i, ii)
    Next
    End If
    Next
    i = .Count + 1
    End With
    Sheets("sheet2").Cells(1).Resize(i, UBound(a, 2)) = a
    End Sub
    Last edited by VBAhelp1; 02-10-2022 at 11:54 AM.

+ 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. Replies: 11
    Last Post: 11-29-2016, 01:00 PM
  2. merge rows with latest date showing
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-28-2015, 01:48 PM
  3. Replies: 2
    Last Post: 04-08-2014, 04:44 AM
  4. Merge Duplicate Rows unique values into single rows for an infinite amount of columns/rows
    By aimeecrystalaid in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-21-2013, 08:43 PM
  5. Delete duplicate rows, but keep the cell that has the latest date
    By vaznlyfe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-20-2012, 01:35 PM
  6. [SOLVED] Merge duplicate rows and merge the columns (approx 10 columns)
    By adfeddon in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-02-2012, 11:19 AM
  7. Using user form choose two columns and find duplicates values
    By midexlis in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-30-2009, 04:23 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