Combine Duplicate data from different worksheets base on cell value

iriex

New Member
Joined
Sep 29, 2013
Messages
3
Please can I get some assistance on the following:
1. Look for duplicates rows throughout the different worksheets using the value under column A (excluding A1).
2. If there are duplicates, ensure that all the possible values combine are listed (excluding duplicate values but including different values). The values for each of the rows (start at C3) are in every other cell and the other cells are just counts (starting at D4) and every other cell depending on the amount of data.
3. Also, for each row, list the name of the worksheets in the same cells that apply to the same data. If the data only appears to be in only one of the worksheet, then just list that worksheet.
4. Data should be listed in ascending order using the numbers in Column A (exluding headinger in A1) and Value should be in ascending order per row as well.
5. Exclude Count data on the consolidated sheet.

Sheet 1

School#
Description
Value
Count
Value
Count
8
Cali
Apple
9990
Grapes
7999
22
Texas
BBQ
8888
Grits
5000
53
Mexico
Tacos
10000
Avacados
6574

<tbody>
</tbody>

Sheet 2

School#
Description
Value
Count
Value
Count
Value
Count
8
Cali
Orange
9990
Grapes
7999
22
Texas
Hot Sauce
8888
Grits
5000
53
Mexico
Tacos
10000
Avacados
6574
1
New York
Hot Dogs
8768
Pizza
23432
Pasta
1500

<tbody>
</tbody>

<tbody>
</tbody>

<tbody>
</tbody>
Expected Outcome (Consolidated Data)
  • Data Under School# is sorted A-Z as well as data in Value per row and the sheet the data appears in is listed as well.
School#
Description
Value
Sheet
1
New York
Hot Dogs
Pasta
Pizza
Sheet2
8
Cali
Apple
Grapes
Orange
Sheet1
Sheet2
22
Texas
BBQ
Grits
Hot Sauce
Sheet1
Sheet2
53
Mexico
Avacados
Tacos
Sheet1
Sheet2

<tbody>
</tbody>

Once I can get that outcome, then I could filter base on the data preferably by Sheet. For example, I would filter contain=Sheet1, my expected outcome would show everything expect the Row with School#=1.

Other important things to note:
  • My excel document has 13 and counting different worksheets, not including the consolidated worksheet.
  • One row data has gone up to column GR (so there is no limitation on how much data one can expect in a row).

This is the macro script i have so far, which I found online as I have no experience at all with macros (willing to learn though). This so far only combines all the data from the different worksheets into one, which is just a start but not my final outcome. I would glady appreciate it if someone can help me with this, as it would take me quite some time to figure out on my own which I'm trying to avoid and need to complete as soon as possible.

Code:
Function LastRow(sh As Worksheet)
    On Error Resume Next
    LastRow = sh.Cells.Find(What:="*", After:=sh.Range("A1"), Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, _
                            SearchDirection:=xlPrevious, MatchCase:=False).Row
    On Error GoTo 0
End Function

Function LastCol(sh As Worksheet)
    On Error Resume Next
    LastCol = sh.Cells.Find(What:="*", After:=sh.Range("A1"), Lookat:=xlPart, _
                            LookIn:=xlFormulas, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False).Column
    On Error GoTo 0
End Function

Sub CopyDataWithHeaders()
    Dim sh As Worksheet
    Dim DestSh As Worksheet
    Dim Last As Long
    Dim shLast As Long
    Dim CopyRng As Range
    Dim StartRow As Long

With Application
    .ScreenUpdating = False
    .EnableEvents = False
End With

' Delete the summary sheet if it exists.
Application.DisplayAlerts = False
On Error Resume Next
ActiveWorkbook.Worksheets("RDBMergeSheet").Delete
On Error GoTo 0
Application.DisplayAlerts = True

' Add a new summary worksheet.
Set DestSh = ActiveWorkbook.Worksheets.Add
DestSh.Name = "RDBMergeSheet"

' Fill in the start row.
StartRow = 2

' Loop through all worksheets and copy the data to the
' summary worksheet.
For Each sh In ActiveWorkbook.Worksheets
    If sh.Name <> DestSh.Name Then

        ' Find the last row with data on the summary
        ' and source worksheets.
        Last = LastRow(DestSh)
        shLast = LastRow(sh)

        ' If source worksheet is not empty and if the last
        ' row >= StartRow, copy the range.
        If shLast > 0 And shLast >= StartRow Then
            'Set the range that you want to copy
            Set CopyRng = sh.Range(sh.Rows(StartRow), sh.Rows(shLast))

           ' Test to see whether there are enough rows in the summary
           ' worksheet to copy all the data.
            If Last + CopyRng.Rows.Count > DestSh.Rows.Count Then
               MsgBox "There are not enough rows in the " & _
               "summary worksheet to place the data."
               GoTo ExitTheSub
            End If

            ' This statement copies values and formats.
            CopyRng.Copy
            With DestSh.Cells(Last + 1, "A")
                .PasteSpecial xlPasteValues
                .PasteSpecial xlPasteFormats
                Application.CutCopyMode = False
            End With

        End If

    End If
    Next

ExitTheSub:

    Application.Goto DestSh.Cells(1)

    ' AutoFit the column width in the summary sheet.
    DestSh.Columns.AutoFit

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub

Thanks.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,215,219
Messages
6,123,690
Members
449,117
Latest member
Aaagu

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