Match WorkSheets back to a Master Worksheet with current years data on it.

anthonyexcel

Active Member
Joined
Jun 10, 2011
Messages
258
Office Version
  1. 365
Platform
  1. Windows
I have 13 sheets of data. Each sheet has about 35000 entries and is set up the same. What I would like to do is take those 13 sheets and bring the second column (Column B) back to a Master Sheet. Column A Contains an ID # Column B the school ID. The master sheet has the current years data (ID in Col A and School in Col B) What I would like to do is bring back Column B from each sheet and place it on the master Sheet if it matches the ID. Thanks in advance!!!!


IDSchool
111111
222212
333311
44446
55557
66663
77772
88881
99998

This is what it would look like:

Book2
ABCDEFGHIJKLMN
1IDCurrentSchool200120202019201820172016201520142013201220112010
2111111616161611111111111111111
3222212909090909090909090909090
4333311454545457878222222
54444612121212124455555
655557615467658989777777
7666634343434367777744
877772616161612222222
98888189898989896677777
1099998222222222222335545
Sheet1
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try:
VBA Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim desWS As Worksheet, i As Long, v1 As Variant, v2 As Variant, ws As Worksheet, dic As Object, lCol As Long
    Set desWS = Sheets("Master")
    v1 = desWS.Range("A2", desWS.Range("A" & Rows.Count).End(xlUp)).Value
    Set dic = CreateObject("Scripting.Dictionary")
    For i = 1 To UBound(v1)
        If Not dic.Exists(v1(i, 1)) Then
            dic.Add v1(i, 1), i + 1
        End If
    Next i
    For Each ws In Sheets
        If ws.Name <> "Master" Then
            lCol = desWS.UsedRange.Columns.Count + 1
            v2 = ws.Range("A2", ws.Range("A" & Rows.Count).End(xlUp)).Resize(, 2).Value
            For i = 1 To UBound(v2, 1)
                If dic.Exists(v2(i, 1)) Then
                    With desWS
                        .Cells(dic(v2(i, 1)), lCol) = v2(i, 2)
                    End With
                End If
            Next i
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Try:
VBA Code:
Sub CopyData()
    Application.ScreenUpdating = False
    Dim desWS As Worksheet, i As Long, v1 As Variant, v2 As Variant, ws As Worksheet, dic As Object, lCol As Long
    Set desWS = Sheets("Master")
    v1 = desWS.Range("A2", desWS.Range("A" & Rows.Count).End(xlUp)).Value
    Set dic = CreateObject("Scripting.Dictionary")
    For i = 1 To UBound(v1)
        If Not dic.Exists(v1(i, 1)) Then
            dic.Add v1(i, 1), i + 1
        End If
    Next i
    For Each ws In Sheets
        If ws.Name <> "Master" Then
            lCol = desWS.UsedRange.Columns.Count + 1
            v2 = ws.Range("A2", ws.Range("A" & Rows.Count).End(xlUp)).Resize(, 2).Value
            For i = 1 To UBound(v2, 1)
                If dic.Exists(v2(i, 1)) Then
                    With desWS
                        .Cells(dic(v2(i, 1)), lCol) = v2(i, 2)
                    End With
                End If
            Next i
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub
Mumps,

Thank you so much!!!!! Worked perfectly!!!! I appreciate your help and guidance!!!!! Have a great day!!!
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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