MurdochQuill
Board Regular
- Joined
- Nov 21, 2020
- Messages
- 84
- Office Version
- 365
- Platform
- Windows
Hi,
I have this code here, which can currently match up single sheets to external references.
So it basically Searches col A on each workbook for matching unique ID's, then brings across the data in col B from the Patcher wb Import sheet.
I'm not sure how I can change this code to cycle through each sheet on the destination workbook (ThisWorkbook, tb), as the LastRw1 is hardcoded to each sheet. I'm a bit stuck on how to enter this in a look so it will make these variables up in the format of "For Each ws In ThisWorkbook" or something like that.
Here's the code so far:
Any help would be really appreciated !
I have this code here, which can currently match up single sheets to external references.
So it basically Searches col A on each workbook for matching unique ID's, then brings across the data in col B from the Patcher wb Import sheet.
I'm not sure how I can change this code to cycle through each sheet on the destination workbook (ThisWorkbook, tb), as the LastRw1 is hardcoded to each sheet. I'm a bit stuck on how to enter this in a look so it will make these variables up in the format of "For Each ws In ThisWorkbook" or something like that.
Here's the code so far:
VBA Code:
Sub Patcher()
Dim lastRw1, lastRw2, nxtRw, m
Dim wb As Workbook
Dim ws As Worksheet
Set tb = ThisWorkbook
For Each wb In Application.Workbooks
If wb.Name Like "Patcher*" And wb.Name <> tb.Name Then
lastRw2 = wb.Sheets("Import").Range("A" & Rows.Count).End(xlUp).Row
lastRw1 = tb.Sheets("Destination").Range("A" & Rows.Count).End(xlUp).Row
End If
For nxtRw = 1 To lastRw2
With tb.Sheets("Destination").Range("A1:A" & lastRw1)
Set m = .Find(wb.Sheets("Import").Range("A" & nxtRw), LookIn:=xlValues, lookat:=xlWhole)
If Not m Is Nothing Then
wb.Sheets("Import").Range("B" & nxtRw & ":O" & nxtRw).Copy _
Destination:=tb.Sheets("Destination").Range("B" & m.Row)
End If
End With
Next
Next wb
End Sub
Any help would be really appreciated !
Last edited: