I'm very new to VBA and I have been trying to develop a tool to merge two sheets with only selected columns of data to output sheet.
I have two sheets with name RCV and MGT. Both have a unique column where it should be matched and paste it on the 3rd sheet which has the name Output.
I tried moving from one cell to another but as the data size too large it takes too long time as the iteration for checking each cell is too high.
The RCV sheet has around 35000 rows of data and MGT sheet has around 25000 rows of data.
Sub Merge_Data()
Dim i, j
Dim k
Dim WS1 As Worksheet
Set WS1 = ThisWorkbook.Sheets("RCV")
Dim WS2 As Worksheet
Set WS2 = ThisWorkbook.Sheets("MGT")
Dim files As Variant
Dim LRow1 As Long
LRow1 = WS1.Range("A" & WS1.Rows.Count).End(xlUp).Row
Dim LRow2 As Long
LRow2 = WS2.Range("A" & WS2.Rows.Count).End(xlUp).Row
k = 3
For i = 2 To LRow1
For j = 2 To LRow2
If Sheets("RCV").Cells(i, "Q").Value = Sheets("RCV").Cells(j, "AD").Value
Then
Sheets("Output").Cells(k, "F").Value = Sheets("RCV").Cells(i, "Q").Value
Sheets("Output").Cells(k, "H").Value = Sheets("RCV").Cells(i, "R").Value
Sheets("Output").Cells(k, "A").Value = Sheets("MGT").Cells(j, "V").Value
k = k + 1
End If
Next
Next
End Sub
Please do help me how to solve this issue. I need to copy multiple columns from RCV sheet and MGT sheet when the condition matches (Column Range from Q2 to Lastrow = AD2 to Lastrow).
The output sheet after merging columns from RCV sheet and MGT sheet: