[英]Excel VBA update links in workbook to same destination
我的问题:
我有一张工作表,在这里我比较两组数据。 这两组数据可能有一些具有相同的描述编号...
在这种情况下,我希望它们合并,但是现在我手动进行。
我的数据看起来在两个范围内:
Date Description Amount
15-12-2017 V576954 -1.289,89
15-12-2017 V576954 1.289,89
15-12-2017 V576954 -1.896,45
19-12-2017 V586894 -789,52
28-12-2017 GS5155692 -9.286,00
28-12-2017 GS5155692 9.286,00
28-12-2017 GS5155692 -11.857,50
目标:
是否可以以某种方式提取出数据透视表正在使用的功能,并用相同的描述总结这些值?
我不想从数据中获取数据透视表,而是要合并具有相同描述,相同日期和相同描述的值的值:)
如果我正确理解了您的问题,那么如果列A和列B中的数据匹配,则希望对列C中的值求和,那么下面的操作将为您完成:
Sub foo()
Sheets("Sheet1").Copy After:=Sheets("Sheet1")
ActiveSheet.Name = "Summary"
Dim ws As Worksheet: Set ws = Sheets("Summary")
'declare and set your worksheet, change Sheet1 to the sheet you are using
LastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
'find the last row with data on Column A
For i = 2 To LastRow 'loop from row 2 to last
ws.Cells(i, 4).FormulaR1C1 = "=SUMIFS(C[-1],C[-2],RC[-2],C[-3],RC[-3])" 'enter sum formula in adjecent cell (Column D)
Next i
ws.Range("D2:D" & LastRow).Copy 'copy the formula
ws.Range("D2:D" & LastRow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False 'paste as values
Range("C2:C" & LastRow).Delete Shift:=xlToLeft 'delete column C and shift the values from column D to column C
ws.Range("$A$1:$D$" & LastRow).RemoveDuplicates Columns:=Array(1, 2, 3, 4), Header:=xlYes 'remove duplicate rows
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.