循环SUM基于2个单元格的标准

时间:2016-08-16 18:14:16

标签: excel-vba vba excel

我需要Excel VBA的一些帮助。

我有3列数据W,X,Y:

What I have

最终结果是将所有X和Y相加,并使用W列中的值更改,得到类似的内容:

What needs to happen

1 个答案:

答案 0 :(得分:1)

让它发挥作用:D

Sub Sort01()

   lRow = 2
   Do While (Cells(lRow, 23) <> "")

    ItemRow1 = Cells(lRow, "Y")
    ItemRow2 = Cells(lRow + 1, "Y")

    lengthRow1 = Cells(lRow, "X")
    lengthRow2 = Cells(lRow + 1, "X")

    If ((ItemRow1 = ItemRow2) And (lengthRow1 = lengthRow2)) Then
        Cells(lRow, "W") = Cells(lRow, "W") + Cells(lRow + 1, "W")
        Rows(lRow + 1).Delete

    Else
        lRow = lRow + 1
    End If
Loop
End sub
相关问题