Consolidate data where same criteria in multiple columns except for amount

Andrei32

New Member
Joined
Apr 27, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi,

I would very much appreciate the help with the following;

1682607968631.png


In the image above, all information in row 3 and 4 are the same except for column J (the amount).
In row 5, the information is unique (hence the doubles count N in the check field that I have created a formula for in column N).
My question is; how can I create a macro or a formula that ensures that when data in field B to I is the same, the amount should be summed up in 1 row instead of two seperate rows.
The reason I need to this is because the program in which I then load the data can only accept one row for each unique "string".

It should also be said that there is no way for me to predefine the strings (for example, a new profit center could be added next month), which is why I can not create a SUM-formula for all potential strings.

Much appreciated!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
can you setup a helper column - see column N - where i concatenate B to I
and then use that with a countifs and a sum - so you get the total sum on the first occurance

and then in column N , i have total

you could use a countifs() for all the columns, but that had issues with blank columns and quite long


if so then maybe something like

Book3
ABCDEFGHIJKLMNO
1
2dupabc1234571abc12345724
3dupabc1234572abc123457 
4dupabc1234573abc123457 
5dupCbc1234574Cbc1234579
6dupCbc1234575Cbc123457 
7UniqEbc1234576Ebc1234576
8dupDbc1234577Dbc12345716
9dupabc1234578abc123457 
10dupDbc1234579Dbc123457 
11dupabc12345710abc123457 
Sheet1
Cell Formulas
RangeFormula
N2:N11N2=B2&C2&D2&E2&F2&G2&H2&I2
O2:O11O2=IF(COUNTIFS($N$2:N2,N2)=1,SUMIFS($J$2:$J$11,$N$2:$N$11,N2),"")


Note: Images are difficult to see , and also requires that I input all the data myself, which means I may make an error, which is very time consuming, and from my point of view less likely to get a response, if a complicated spreadsheet. Plus we cannot see any of the formulas used.

Therefore -

A SMALL sample spreadsheet, around 10-20 rows, would help a lot here, with all sensitive data removed, and expected results mocked up and manually entered, with a few notes of explanation.

MrExcel has a tool called “XL2BB” that lets you post samples of your data and will allow us to copy/paste your sample data into our Excel spreadsheets, saving a lot of time.

You can also test to see if it works ok, in the "Test Here" forum.

OR if you cannot get XL2BB to work, or have restrictions on your PC

then put the sample spreadsheet onto a share

I only tend to goto OneDrive, Dropbox or google docs , as I'm never certain of other random share sites and possible virus.
Please make sure you have a representative data sample and also that the data has been desensitised, remember this site is open to anyone with internet access to see - so any sensitive / personal data should be removed

Make sure you set any share or google to share to everyone
 
Upvote 0
Welcome to Mr Excel Andrei32

I had an idea that may work for you but I'm not sure if columns G to I and K and L will ever have any data in them.
Let me know about this.

Give this a go. Put this code in a standard code module.
Let me know if you need help.

It puts the results into another worksheet, 'Results' in my code.

You will need to create a new worksheet and change these two lines to reflect the names of your worksheets.

Set Ws = Worksheets("Consolidate")
Set WsResults = Worksheets("Results")


VBA Code:
Public Sub subConsolidate()
Dim Ws As Worksheet
Dim WsResults As Worksheet
Dim lngRows As Long
Dim strFormula As String
Dim rng As Range

    ActiveWorkbook.Save
    
    Set Ws = Worksheets("Consolidate")
    Set WsResults = Worksheets("Results")
    
    WsResults.Cells.Clear
                
    Ws.Range("B2:L2").Copy Destination:=WsResults.Range("B2")
    Ws.Range("B2:L2").Copy
    WsResults.Range("B2").PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    
    lngRows = Ws.Range("B2").End(xlDown).Row
    
    WsResults.Range("B3").Formula2 = "=UNIQUE(" & Ws.Name & "!$B$3:$F" & lngRows & ",FALSE,FALSE)"
    
    Set rng = Ws.Range("A3:A" & lngRows)
    
    lngRows = WsResults.Range("B2").End(xlDown).Row
        
    WsResults.Range("J3:J" & lngRows).Formula = "=SUMIFS(" & Ws.Name & "!$J$3:$J$14," & _
        Ws.Name & "!" & rng.Offset(0, 1).Address & "," & WsResults.Name & "!$B3," & _
        Ws.Name & "!" & rng.Offset(0, 2).Address & "," & WsResults.Name & "!$C3," & _
        Ws.Name & "!" & rng.Offset(0, 3).Address & "," & WsResults.Name & "!$D3," & _
        Ws.Name & "!" & rng.Offset(0, 4).Address & "," & WsResults.Name & "!$E3," & _
        Ws.Name & "!" & rng.Offset(0, 5).Address & "," & WsResults.Name & "!$F3," & _
        Ws.Name & "!" & rng.Offset(0, 6).Address & "," & WsResults.Name & "!$G3," & _
        Ws.Name & "!" & rng.Offset(0, 7).Address & "," & WsResults.Name & "!$H3)"
                             
        With WsResults.Range("B2:L" & lngRows)
            .Value = .Value
            .VerticalAlignment = xlCenter
            With .Borders
                .LineStyle = xlContinuous
                .Weight = xlThin
               .ColorIndex = vbBlack
            End With
        End With
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,269
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top