我有一个非常大的excel文件,大约50K行。在列(C)中我有人员编号1,1,1,1,2,3,4,5,....在列(N)中,我有这个人的付款,所以数据看起来像< / p>
我想要的是从N列汇总一个人的所有付款,并将结果设置在O列,然后合并O列。
答案 0 :(得分:1)
看起来您正在寻找内置的Excel SUMIF
功能
=sumif(C:C,"specific person number",N:N)
答案 1 :(得分:0)
Sub summAndMerge()
lastrow = Worksheets("A").Range("A65536").End(xlUp).Row
For i = 2 To lastrow
If Cells(i, 1).Value <> Cells(i - 1, 1).Value And Cells(i, 1).Value <> Cells(i + 1, 1).Value Then
intUpper = i
Debug.Print ("<> -1 and <> +1 " & intUpper)
End If
If Cells(i, 1).Value <> Cells(i - 1, 1).Value And Cells(i, 1).Value = Cells(i + 1, 1).Value Then
intUpper = i
Debug.Print ("<> -1 and = +1 " & intUpper & " UPPPER LIMIT")
End If
If Cells(i, 1).Value <> Cells(i + 1, 1).Value And Cells(i, 1).Value = Cells(i - 1, 1).Value Then
Application.DisplayAlerts = False
Debug.Print ("<> +1 and = -1:" & i & "LOWER LIMIT")
Range(Cells(intUpper, 3), Cells(i, 3)).Merge
Cells(intUpper, 3).Value = "=sumif(B" & CStr(intUpper) & ":B" & CStr(i) & ","">0"")"
Range(Cells(i, 1), Cells(i, 24)).Borders(xlEdgeBottom).LineStyle = xlDouble
End If
If Cells(i, 1).Value <> Cells(i + 1, 1).Value And Cells(i, 1).Value <> Cells(i - 1, 1).Value Then
Debug.Print ("One Cells: " & i)
Range(Cells(i, 1), Cells(i, 24)).Borders(xlEdgeBottom).LineStyle = xlDouble
Cells(intUpper, 3).Value = Cells(intUpper, 2).Value
End If
Next i
End Sub