Excel - Find duplicates in one column then sum quantities into another column?

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-05 12:15:24

问题


Find duplicates in one column then sum quantities into another column

DATA       RESULT   

A  1       A  11
A  1       B  7
A  9       C  5
B  2       D  4
B  2       E  8
B  3            
C  5            
D  4            
E  7            
E  1    

回答1:


For EXCEL 365 (or the Excel web app):

In C1 enter:

=UNIQUE(A1:A10)

in D1 enter:

=SUMIF(A1:A10,C1#,B1:B10)

EDIT#1:

If VBA is acceptable to you, then try:

Public Function unikue(rng As Range)
    Dim arr, c As Collection, r As Range
    Dim nCall As Long, nColl As Long
    Dim i As Long
    Set c = New Collection
    
    nCall = Application.Caller.Count
    
    On Error Resume Next
        For Each r In rng
            c.Add r.Text, CStr(r.Text)
        Next r
    On Error GoTo 0
    nColl = c.Count
    
    
    If nCall > nColl Then
        ReDim arr(1 To nCall, 1 To 1)
        For i = 1 To nCall
            arr(i, 1) = ""
        Next i
    Else
        ReDim arr(1 To nColl, 1 To 1)
    End If
    
    For i = 1 To nColl
        arr(i, 1) = c.Item(i)
    Next i
    
    unikue = arr
End Function



回答2:


DISCLAIMER: This is about our tool esProc. We have been told it’s an easy and obvious way to Group Excel Worksheets.

A1=file("D:/data.xlsx").xlsimport()
A2=A1.groups(_1;sum(_2))
A3=file("D:/result.xlsx").xlsexport(A2)

More detail see this post:Group & Summarize an XLS file without Using Excel



来源:https://stackoverflow.com/questions/64182673/excel-find-duplicates-in-one-column-then-sum-quantities-into-another-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!