Copy and paste multiple matching (multiple sheet) then insert rows to a new sheet

SamKhem

Board Regular
Joined
Mar 18, 2024
Messages
50
Office Version
  1. 2016
Platform
  1. Windows
Dear Senior member

I found this vba running code in our group but I need to loop value in multiple sheet then show result in new sheet. But code below loop only one sheet. Please help to guide add some code (loop multiple sheet).

Sub CopyPartsForReview()

Dim wb As Workbook
Dim shtMaster As Worksheet, shtReview As Worksheet, shtOut As Worksheet
Dim rowLastMstr As Long, rowLastRev As Long
Dim rngMstr As Range, rngRev As Range
Dim arrMstr As Variant, arrRev As Variant, arrOut As Variant
Dim dictRev As Object, dictKey As String
Dim i As Long, j As Long, rowOut As Long

Set wb = ActiveWorkbook
Set shtMaster = wb.Worksheets("Master")
Set shtReview = wb.Worksheets("Review")

With shtMaster
rowLastMstr = .Range("C" & Rows.Count).End(xlUp).Row
Set rngMstr = .Range("A1:O" & rowLastMstr)
arrMstr = rngMstr.Value2
End With

ReDim arrOut(1 To UBound(arrMstr, 1), 1 To UBound(arrMstr, 2))

With shtReview
rowLastRev = .Range("A" & Rows.Count).End(xlUp).Row
Set rngRev = .Range("A2:A" & rowLastRev)
arrRev = rngRev.Value2
End With

Set dictRev = CreateObject("Scripting.dictionary")
dictRev.CompareMode = vbTextCompare

' Review Parts into Dictionary
For i = 1 To UBound(arrRev)
dictKey = arrRev(i, 1)
If Not dictRev.exists(dictKey) Then
dictRev(dictKey) = i
End If
Next i

For i = 2 To UBound(arrMstr)
dictKey = arrMstr(i, 3)
If dictRev.exists(dictKey) Then
rowOut = rowOut + 1
For j = 1 To UBound(arrMstr, 2)
arrOut(rowOut, j) = arrMstr(i, j)
Next j
End If
Next i

If rowOut > 0 Then
With wb
Set shtOut = .Sheets.Add(After:=.Worksheets(.Worksheets.Count))
End With

With shtOut
rngMstr.Rows(1).Copy Destination:=.Range("A1")
.Range("A2").Resize(rowOut, UBound(arrOut, 2)).Value = arrOut
.Columns("A").Resize(, UBound(arrOut, 2)).AutoFit
End With
End If

End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Dear Senior Member

I would like request you to make vba run on excel around a million rows as below by look up value (Sheet"Input") loop to sheet name ("Data1", "Data2","Data3","Data4") then show result in Sheet"Result".
Sheet "Input"
Column A
RP010001
RP010002
RP010003
RP010004
RP010005
RP010006
RP010007
RP010008
RP010009
RP010010
RP010011
RP010012
RP010013
Sheet"Data1"
GRN NoLine NoPart NoDescriptionGroup CodeCategoryLocationQty LeftUOMUOPUnit Of ConvStatus IDStatusblnShowInDropdownLifed Item
109221RP010001SR-30 SOLUBLE RELEASE SUPPORT CANISTER FORTUS PLUS 0355-03110 - 4503D PRINTINGG5A1EAEA11LiveTRUEFALSE
106761RP010002SR-30 SOLUBLE RELEASE SUPPORT CANISTER FORTUS PLUS 0355-03110 - 4503D PRINTINGG5A5EAEA11LiveTRUEFALSE
106762RP010003ABS-M30 FILAMENT CANISTER FORTUS PLUS NATURAL 0355-021103D PRINTINGG6A6EAEA11LiveTRUEFALSE
Sheet"Data2"
GRN NoLine NoPart NoDescriptionGroup CodeCategoryLocationQty LeftUOMUOPUnit Of ConvStatus IDStatusblnShowInDropdownLifed Item
73071RP010004ABS-M30 FILAMENT CANISTER FORTUS PLUS NATURAL 0355-021103D PRINTINGG6A2EAEA11LiveTRUEFALSE
10031RP010005ABS-M30 FILAMENT CANISTER FORTUS PLUS BLACK 0355-021123D PRINTINGG7A1EAEA11LiveTRUEFALSE
10041RP010006SR-30 SUPPORT CARTRIDGE (FORTUS 250MC) 0340-305003D PRINTINGG8A5EAEA11LiveTRUEFALSE
Sheet"Data3"
GRN NoLine NoPart NoDescriptionGroup CodeCategoryLocationQty LeftUOMUOPUnit Of ConvStatus IDStatusblnShowInDropdownLifed Item
10051RP010007P430 DIMENSION ABS PLUS MATERIAL CASSETTE WHITE 0340-212013D PRINTINGG9A8EAEA11LiveTRUEFALSE
49945RP010008FOUNDATION SHEET SMALL FORTUS 450/900MC 0325-002753D PRINTINGG7B60EAPK201LiveTRUEFALSE
10071RP010009ULTEM 1010 MODEL FORTUS 450MC NATURAL 0355-023303D PRINTINGG10A3EAEA11LiveTRUEFALSE
Sheet"Data4"
GRN NoLine NoPart NoDescriptionGroup CodeCategoryLocationQty LeftUOMUOPUnit Of ConvStatus IDStatusblnShowInDropdownLifed Item
10081RP010010ULTEM 1010 SUPPORT FORTUS 450MC NATURAL 0355-032403D PRINTINGG11A4EAEA11LiveTRUEFALSE
10091RP010011ABS-M30I FILAMENT CANISTER FORTUS PLUS NATURAL 0355-021203D PRINTINGG12A3EAEA11LiveTRUEFALSE
66061RP010012ABRANET DISC 150MM P80ABRASIVESE3A1boxbox11LiveTRUEFALSE
42733RP010013ABRANET DISC 150MM P80ABRASIVESE3A2boxbox11LiveTRUEFALSE
Sheet"Result"
NoLine NoPart NoDescriptionGroup CodeCategoryLocationQty LeftUOMUOPUnit Of ConvStatus IDStatusblnShowInDropdownLifed Item
109221RP010001SR-30 SOLUBLE RELEASE SUPPORT CANISTER FORTUS PLUS 0355-03110 - 4503D PRINTINGG5A1EAEA11LiveTRUEFALSE
106761RP010002SR-30 SOLUBLE RELEASE SUPPORT CANISTER FORTUS PLUS 0355-03110 - 4503D PRINTINGG5A5EAEA11LiveTRUEFALSE
106762RP010003ABS-M30 FILAMENT CANISTER FORTUS PLUS NATURAL 0355-021103D PRINTINGG6A6EAEA11LiveTRUEFALSE
73071RP010004ABS-M30 FILAMENT CANISTER FORTUS PLUS NATURAL 0355-021103D PRINTINGG6A2EAEA11LiveTRUEFALSE
10031RP010005ABS-M30 FILAMENT CANISTER FORTUS PLUS BLACK 0355-021123D PRINTINGG7A1EAEA11LiveTRUEFALSE
10041RP010006SR-30 SUPPORT CARTRIDGE (FORTUS 250MC) 0340-305003D PRINTINGG8A5EAEA11LiveTRUEFALSE
10051RP010007P430 DIMENSION ABS PLUS MATERIAL CASSETTE WHITE 0340-212013D PRINTINGG9A8EAEA11LiveTRUEFALSE
49945RP010008FOUNDATION SHEET SMALL FORTUS 450/900MC 0325-002753D PRINTINGG7B60EAPK201LiveTRUEFALSE
10071RP010009ULTEM 1010 MODEL FORTUS 450MC NATURAL 0355-023303D PRINTINGG10A3EAEA11LiveTRUEFALSE
10081RP010010ULTEM 1010 SUPPORT FORTUS 450MC NATURAL 0355-032403D PRINTINGG11A4EAEA11LiveTRUEFALSE
10091RP010011ABS-M30I FILAMENT CANISTER FORTUS PLUS NATURAL 0355-021203D PRINTINGG12A3EAEA11LiveTRUEFALSE
66061RP010012ABRANET DISC 150MM P80ABRASIVESE3A1boxbox11LiveTRUEFALSE
42733RP010013ABRANET DISC 150MM P80ABRASIVESE3A2boxbox11LiveTRUEFALSE

Thank in advance for you support.
 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,595
Members
452,657
Latest member
giadungthienduyen

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