MurdochQuill
Board Regular
- Joined
- Nov 21, 2020
- Messages
- 84
- Office Version
- 365
- Platform
- Windows
Hi all,
I'm using the following subroutine to stitch values from sheet "Stitch" col E to sheet "Sheet 1" col O
If it is a match, we then copy data from col F & G into col L & K onto Sheet 1.
This works if I have ONE match for each value in col E on "Stitch". But after using it for a while I have found I have multiple matches on "Sheet 1" col O. How would I rework the following so if it finds more than one match it can copy the data to ALL matches rather than just the first encountered match?
I'm using the following subroutine to stitch values from sheet "Stitch" col E to sheet "Sheet 1" col O
If it is a match, we then copy data from col F & G into col L & K onto Sheet 1.
This works if I have ONE match for each value in col E on "Stitch". But after using it for a while I have found I have multiple matches on "Sheet 1" col O. How would I rework the following so if it finds more than one match it can copy the data to ALL matches rather than just the first encountered match?
VBA Code:
Sub StitchRunsComms()
Application.ScreenUpdating = False
Dim lastRw1, lastRw2, nxtRw, m
Dim wb As Workbook
Set ws = ThisWorkbook.Worksheets("Sheet 1")
Set tb = ThisWorkbook
' *** Logic for stitching back together ***
With tb.Worksheets("Sheet 1")
lastRw1 = ws.Range("O" & Rows.Count).End(xlUp).Row
lastRw2 = Sheets("Stitch").Range("E" & Rows.Count).End(xlUp).Row
For nxtRw = 1 To lastRw2
With ws.Range("O2:O" & lastRw1)
Set m = .Find(tb.Sheets("Stitch").Range("E" & nxtRw), LookIn:=xlValues, lookat:=xlWhole)
If Not m Is Nothing Then
tb.Sheets("Stitch").Range("F" & nxtRw).Copy
ws.Range("L" & m.Row).PasteSpecial xlValues
tb.Sheets("Stitch").Range("G" & nxtRw).Copy
ws.Range("K" & m.Row).PasteSpecial xlValues
End If
End With
Next
End With
tb.Worksheets("Stitch").Range("E1:G1001").Clear
End Sub