excel vba,如果A列相同,则对应b列数据求和。A 1
A 2
A 3
B 2
B 3
B 4
C 3
C 4
最后输出:
A 6
B 9
C 7
这样
excel vba,如果A列相同,则对应b列数据求和。
答案:1 悬赏:0 手机版
解决时间 2021-03-08 07:47
- 提问者网友:回忆在搜索
- 2021-03-07 18:19
最佳答案
- 五星知识达人网友:玩家
- 2021-03-07 19:38
参考:
Sub SumCalculation()
Dim FirstRow As Long, LastRow As Long
Dim MyCpt As Long
Dim F As Range
Dim I As Long
Dim MyFormula As String
Application.ScreenUpdating = False
FirstRow = 2
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range(Cells(FirstRow, "B"), Cells(LastRow, "B")).ClearContents
For I = FirstRow To LastRow
If (Cells(I, "A") <> "") Then
MyFormula = "COUNTIF(A" & FirstRow & ":A" & I & ",A" & I & ")"
MyCpt = Evaluate(MyFormula)
If (MyCpt = 1) Then
MyFormula = "SUMPRODUCT((A" & FirstRow & ":A" & LastRow & "=A" & I & ")*(C" & FirstRow & ":C" & LastRow & "))"
Cells(I, "B") = Evaluate(MyFormula)
End If
End If
Next I
Application.ScreenUpdating = True
End Sub
Sub SumCalculation()
Dim FirstRow As Long, LastRow As Long
Dim MyCpt As Long
Dim F As Range
Dim I As Long
Dim MyFormula As String
Application.ScreenUpdating = False
FirstRow = 2
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range(Cells(FirstRow, "B"), Cells(LastRow, "B")).ClearContents
For I = FirstRow To LastRow
If (Cells(I, "A") <> "") Then
MyFormula = "COUNTIF(A" & FirstRow & ":A" & I & ",A" & I & ")"
MyCpt = Evaluate(MyFormula)
If (MyCpt = 1) Then
MyFormula = "SUMPRODUCT((A" & FirstRow & ":A" & LastRow & "=A" & I & ")*(C" & FirstRow & ":C" & LastRow & "))"
Cells(I, "B") = Evaluate(MyFormula)
End If
End If
Next I
Application.ScreenUpdating = True
End Sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯