Combining Multiple Sheets without duplicates and organising data into unique columns

Brick Transport

New Member
Joined
Nov 17, 2017
Messages
22
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. Mobile
  3. Web
Hello, I have turned to MrExcel numerous times in the past for solutions to various problems I've encountered and found the help to be excellent! Well, now I have something that I am struggling to find an adequate solution to. I hope that someone can help me out.

So, I have 7 worksheets of "Top Customers" for the last 7 financial years. I want to combine these into one sheet, without duplicating the customers and arrange the t/o values into individual columns relating to the particular financial year:

Turnover
CUSTOMER 2010201120122013201420152016

<tbody>
</tbody>

<tbody>
</tbody>
The data is stored in each separate sheet with "customer name" in Column B & "turnover" in Column C, however the number of customers in each sheet varies. The Sheets are called Top Customers 2009-10, Top Customers 2010-11 etc etc, for example:

Customer T/O
J.Smith Ltd £188,341.73
J. Brown Ltd £61,972.91
J. Green Ltd £59,364.78
J. Red Ltd £30,572.22
J. Black Ltd £24,600.02
J. Jones Ltd £22,273.99

<tbody>
</tbody>

and so on.

How do I then take Column B from each sheet and combine them all into Column B of the master, avoiding duplicates and then take the corresponding t/o value from Column B in each sheet and transfer that into the relevant year column for the corresponding customer on the master sheet?

I'm not even sure if this is possible to do or not, but I've tried a few of the solutions posted here about combining columns etc but none seem to work with it being fairly complex.

Any help would be greatly appreciated as this is driving me bonkers trying to figure out!!! Please let me know if further information or a sample of the data would help and I can arrange that.

Huge thanks in advance,
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi & welcome to the board.
Try this
Code:
Sub CopyData()

    Dim Ws As Worksheet
    Dim MstSht As Worksheet
    Dim NxtRw As Long
    Dim Col As Long
    Dim Rng As Range
    Dim Cl As Range
    
    Set MstSht = Sheets("Master")
    For Each Ws In Worksheets
        If Not Ws.Name = "Master" Then
            Col = Right(Ws.Name, 2) - 8
            NxtRw = MstSht.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
            With Ws.Range("B2", Ws.Range("B" & Rows.Count).End(xlUp))
                .Copy MstSht.Range("A" & NxtRw)
                .Offset(, 1).Copy MstSht.Cells(NxtRw, Col)
            End With
        End If
    Next Ws
    With CreateObject("scripting.dictionary")
        For Each Cl In MstSht.Range("A2", MstSht.Range("A" & Rows.Count).End(xlUp))
            If Not .exists(Cl.Value) Then
                .Add Cl.Value, Cl.Row
            Else
                Cl.End(xlToRight).Copy MstSht.Cells(.Item(Cl.Value), Cl.End(xlToRight).Column)
                If Rng Is Nothing Then
                    Set Rng = Cl
                Else
                    Set Rng = Union(Rng, Cl)
                End If
            End If
        Next Cl
    End With
    Rng.EntireRow.Delete
            
End Sub
 
Upvote 0
Hi Fluff,

Thanks for the code. Its not quite what I was looking for though - this copy's the T/O column on each sheet and transfers them all into column A of the master sheet. What am I trying to do is to take each year and combine them into one sheet with a row per customer, and turnover for each year in a separate column. The top customers can fluctuate between years.

For example in 2010 the top 5 customers were J Smith; £200,000 , J Green - £35,000, J Brown - £34,000 J Red - £20,000 & J Black - £19,500, but in 2011 the top 5 were J Green - £600,000, J Black - £450,000, J Blue - £35,000, J Smith - £30,000 and J Pink - £19,775 and so on. What I would like to do is collate the data from each sheet then into the master thus:

Turnover
CUSTOMER2010201120122013201420152016
J Smith £ 200,000.00 £ 30,000.00
J Green £ 35,000.00 £ 600,000.00
J Brown £ 34,000.00 £ -
J Red £ 20,000.00 £ -
J Black £ 19,500.00 £ 450,000.00
J Blue £ - £ 35,000.00
J Pink £ - £ 19,775.00

<colgroup><col><col span="2"><col span="5"></colgroup><tbody>
</tbody>

Does this make sense? I'm trying to get column A to list all of the top customers once only and then columns B-H to list their respective T/O for each year.
 
Upvote 0
In your op you said that the sheet names were called Top Customers 2009-10 etc, is this correct?
 
Upvote 0
yes, in total there are 7: Top Customers 2009-10, 2010-11, 2011-12, 2012-13, 2013-14, 2014-15 & 2015-16, and then Master.
 
Upvote 0
I should point out that I don't necessarily need Master to be in any particular order as I can filter & sort once all the data has been transferred
 
Upvote 0
Try adding a msgbox like this
Code:
            Col = Right(Ws.Name, 2) - 8
            MsgBox Col
            NxtRw = MstSht.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
& step through the code using F8. does the msgbox show 2, then 3 etc?
 
Upvote 0
OK, yes it does, but it still only transfers the T/O into Column A....
 
Upvote 0
On the individual sheets do you have a header in row 1 with data starting in row 2?
Also do you have any merged cells in any sheet?
 
Upvote 0
Hi, no there's no merged cells in any of the sheets. In the Top Customers sheets row 1 is a header: A1: Customer Name; A2: T/O and in Master rows 1 & 2 are headers:

Turnover
CUSTOMER2010201120122013201420152016

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

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