B4andafter
New Member
- Joined
- Aug 9, 2017
- Messages
- 30
- Office Version
- 365
- Platform
- Windows
Hello, I am having a difficult time figuring out a way to copy rows based on cell value in column E from source worksheet Sheet 1 to Sheet 2 Master file. I would like to paste below corresponding matching cells value in column E and leave empty space between different amounts. See snippts below. Also, it would be great if you can help me list the ones that were not found. Thank you all in advance.
Sheet1 (Source)
Sheet2 (Master File)
RESULTS:
Below is the code I am using but is not working properly.
Warm Regards,
Bfandafter from Houston, TX
Sheet1 (Source)
Sheet2 (Master File)
RESULTS:
Below is the code I am using but is not working properly.
VBA Code:
Sub transfer()
Dim i As Long, j As Long, lastrow2 As Long
Dim lastrow1 As Long
Dim FinalRow As Long
Dim myNum As Integer
Dim LastRowPFW As Integer
Sheets(1).Select
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To FinalRow
myNum = Sheets(1).Cells(i, 5).Value
Sheets(2).Activate
lastrow2 = Sheets(2).Cells(Rows.Count, 1).End(xlUp).Row
For j = 2 To lastrow2
If Sheets(2).Cells(j, 5).Value = myNum Then
Sheets(1).Activate
Sheets(1).Range(Cells(i, 1), Cells(i, 5)).Copy
Sheets(2).Activate
LastRowPFW = Range("A:E").Find(what:=myNum, after:=Range("A" & i & ":E" & i), searchdirection:=xlPrevious).Row
Sheets(2).Range(Cells(j, 1), Cells(j, 5)).Select.Offset(1).Row
ActiveSheet.Paste
End If
Next j
Application.CutCopyMode = False
Next i
Sheets(1).Activate
Sheets(1).Cell(“E2”).Select
End Sub
Warm Regards,
Bfandafter from Houston, TX