有没有一个简单的方法来总结一个excel表格中的行和列重复?

wyyhbhjk  于 12个月前  发布在  其他
关注(0)|答案(2)|浏览(78)

我有一个文件,第一列列出了零件,这些零件重复出现,在之后的每一列中,我有这些零件的位置,这些零件确实根据日期重复出现。
我需要总结成一个单一的工作表,行或列重复,他们只是“sumif”行和列是相同的。
总结一下:
x1c 0d1x的数据
变成这样:



首先,我试图循环通过行和列找到重复和总和在一起。灾难,在简单的10 x 10表去罚款,但整个文件有600+行和700+列,它循环了几个小时,我不得不重新启动PC。目前我正试图使用MySQL复制选择,粘贴转置在临时表,排序,然后:

For i = filterLastRow To 1 Step -1

    If shtFCol.Range("B" & i) = shtFCol.Range("B" & i - 1) Then
        For j = 6 To LastCol
            shtFCol.Range("B" & i - 1) = shtFCol.Range("B" & i - 1) + shtFCol.Range("B" & i)
        Next j
        shtFCol.Rows(i).EntireRow.Delete
        i = i - 1
    End If
Next i

字符串
粘贴回原始数据并对所有行重复此过程。是否有更简单/更快的方法?

ulydmbyx

ulydmbyx1#

这里有一个方法。结果放在一个单独的表中。

Sub test()
    Dim wsResult As Worksheet
    Dim rng As Range, arr, r As Long, c As Long, mR, mC
    
    Set wsResult = ThisWorkbook.Worksheets("Result")          'sheet for result
    wsResult.Cells.ClearContents
    
    Set rng = ThisWorkbook.Worksheets("Data").Range("B4:I12") 'source data
    arr = rng.Value
    
    For r = 2 To UBound(arr, 1)        'loop input rows from row 2
        mR = Application.Match(arr(r, 1), wsResult.Columns(1), 0) 'already have row header?
        If IsError(mR) Then 'if no mtch found...
            mR = wsResult.Cells(Rows.Count, 1).End(xlUp).row + 1 'next empty cell in column A
            wsResult.Cells(mR, 1).Value = arr(r, 1)              'add the row header
        End If
        For c = 2 To UBound(arr, 2)   'loop input columns
            mC = Application.Match(arr(1, c), wsResult.Rows(1), 0) 'follow same process as for row headers
            If IsError(mC) Then
                mC = wsResult.Cells(1, Columns.Count).End(xlToLeft).Column + 1
                wsResult.Cells(1, mC).Value = arr(1, c)
            End If
            With wsResult.Cells(mR, mC)
                .Value = .Value + 1  'increment the count for this unique pair of row/column label
            End With
        Next c
    Next r
End Sub

字符串

von4xj4u

von4xj4u2#

您可以使用data. from table/range [ ] header将范围带入PowerQuery
x1c 0d1x的数据
进入主页...高级编辑器...然后从下面粘贴。使用自动生成的第一行代替我的行来保留您的范围名称

let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], //use your auto generated first row in place of this one
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Promoted Headers", {"Column1"}, "Attribute", "Value"),
Split_Dupes = Table.TransformColumns(#"Unpivoted Other Columns",{{"Attribute", each Text.BeforeDelimiter(_,"_"), type text}}),
#"Pivoted Column" = Table.Pivot(Split_Dupes, List.Distinct(Split_Dupes[Attribute]), "Attribute", "Value", List.Sum)
in #"Pivoted Column"

字符串
文件.关闭并加载.表格回Excel
右键单击并在需要时刷新表,或重新刷新powerquery


相关问题