简体   繁体   中英

Excel VBA update links in workbook to same destination

My issue:

I have a sheet, where I compare two sets of data. These two sets of data, are might have some with the same description number...

In this case I want them to merge, but at the moment I do it manually..

My data looks like in both ranges:

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  

GOAL:

Is there somehow, that I can pull out the Functions a Pivot Table is using, and sum up the values with the same description??
I don't want to get a Pivot Table out of my data, I want to merge the values of the values, which has the same description, along as having the same Date, and the same description :)

If I understand your question correctly, you want to sum the values on Column C if the data in Column A and B match, then the following would do that for you:

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

You can use Power Pivot it is a free add-in that you can get and easily activate. Get & Transform by default in Excel 2016.

  1. Select any cell in your main table.
  2. Go to Power Pivot Tab or Data in Excel 2016.
  3. Select Form Table/Range -> OK

It will open the Query Editor there:

  1. Select the columns [Date] and [Description]
  2. Go to Home tab and select Group by
  3. Put a name for the new field.
  4. Select the operation.
  5. Select the column to Sum.
  6. OK
  7. Go Home tab select Close & Load
  8. Play with your new data!

在此处输入图片说明

You can connect many sources to Power Query and it will be a right click Refresh and you will have your process done!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM