+ Reply to Thread
Results 1 to 2 of 2

Data Consolidation

Hybrid View

  1. #1
    Registered User
    Join Date
    04-06-2007
    Posts
    1

    Data Consolidation

    I have a spreadsheet with duplicate data in column 1 (Names of Customers). Each row contains the name of a customer and a record of their purchases, including a column for amounts. I have a VBA macro to eliminate the duplicate rows based on the names in Column 1 (see below). However, I want to consolidate the total purchases so that I end up with 1 row per customer and the total dollar value of their purchases in the cell for Amounts.

    VBA:
    Public Sub DeleteDuplicateRows() 
        '
         'This macro deletes duplicate rows in the selection. Duplicates are
         'counted in the COLUMN of the active cell.
        Dim Col As Integer 
        Dim r As Long 
        Dim C As Range 
        Dim N As Long 
        Dim V As Variant 
        Dim Rng As Range 
        On Error Goto EndMacro 
        Application.ScreenUpdating = False 
        Application.Calculation = xlCalculationManual 
        Col = ActiveCell.Column 
        If Selection.Rows.Count > 1 Then 
            Set Rng = Selection 
        Else 
            Set Rng = ActiveSheet.UsedRange.Rows 
        End If 
        N = 0 
        For r = Rng.Rows.Count To 1 Step -1 
            V = Rng.Cells(r, 1).Value 
            If Application.WorksheetFunction.CountIf(Rng.Columns(1), V) > 1 Then 
                Rng.Rows(r).EntireRow.Delete 
                N = N + 1 
            End If 
        Next r 
    EndMacro: 
        Application.ScreenUpdating = True 
        Application.Calculation = xlCalculationAutomatic 
    End Sub

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    Sum Duplicate rows before deleting duplicate rows

    Hi,
    Try out this example,
    click on the reset button to reset sheet
    click the other button to run the macro
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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