我有一個看起來像這樣的數據:Excel的VBA合併重複的行,並添加量
Col A | Col B | Col C
name 1| Item 1| 3
name 2| Item 3| 1
name 3| Item 2| 2
name 2| Item 3| 6
name 3| Item 2| 4
name 2| Item 3| 3
我需要一行代碼添加量的最後一列重複的行,然後刪除重複的行。所以上面的表應該是這樣的:
Col A | Col B | Col C
name 1| Item 1| 3
name 2| Item 3| 10
name 3| Item 2| 6
我已經嘗試了多種方法,從其他人的問題,但我不斷收到「錯誤:400」。
下面是兩個例子:
For Each a In tm.Range("B2", Cells(Rows.Count, "B").End(xlUp))
For r = 1 To Cells(Rows.Count, "B").End(xlUp).Row - a.Row
If a = a.Offset(r, 0) And a.Offset(0, 1) = a.Offset(r, 1) And a.Offset(0, 2) = a.Offset(r, 2) Then
a.Offset(0, 4) = a.Offset(0, 4) + a.Offset(r, 4)
a.Offset(r, 0).EntireRow.Delete
r = r - 1
End If
Next r
Next a
With Worksheets("Card Test")
With .Range("b2:e2").Resize(.Cells(.Rows.Count, 1).End(xlUp).Row)
.Copy
With .Offset(, .Columns.Count + 1)
.PasteSpecial xlPasteAll ' copy value and formats
.Columns(2).Offset(1).Resize(.Rows.Count - 1, 2).FormulaR1C1 = "=SUMIF(C1,RC1,C[-" & .Columns.Count + 1 & "])"
.Value = .Value
.RemoveDuplicates 1, xlYes
End With
End With
End With
另外我應該指出,我有兩個工作表和使用宏將是在一個不同的片材比數據的按鈕。這似乎也造成了問題。
大,這完美的作品!我所需要做的就是將單元格引用添加到其他工作表(tm)中): –