I am quite new or intermediate learner to vba programing and came up with a task to copy a cell value from workbook1 of sheet1 to workbook2 of sheet1 by matching up with multiple criteria and copy the Sort reference(workbook1) column cell value to Notes And Assumption(workbook2) cells.
Workbook1 Column Workbook2 Column Functional Group matches with-------> Primary Skills
LOB matches with-------> Service Line
Region/Country matches with-------> Work Required Country
Sort Reference(Workbook1)-------------------> Notes And Assumptions(Workbook2) (Note:- Matching the criteria and copy the corresponding row Sort Reference value to column Notes and Assumptions)
Destination Workbook2 Column to match Criteria to match from workbook2
Source Workbook1 columns are Criteria to match from workbook1
Demo of Output Output of workbook2 in Notes And Assumptions Column Note:- Output should be like this as given in Image and if not data found leave blank
I tried below but not getting the result because if the criteria gets matched and values get pasted in a particular column then that matched row should not repeat again and it starts from the next row to match. Because of this my values get override.
Sub sortref()
Dim wbk, wbk1 As Workbook
Dim sht, sht1 As Worksheet
Dim i, j, k, n, m As Long
Dim FGroup, PSkills, RegCoun, WrCoun, MRCode, RCode As String
Application.DisplayAlerts = False
Set wbk = Workbooks.Open(Filename:="C:\Users\611892636\desktop\RMT Changes\RMT v8.0.2 - Huawei V1.2.xlsm")
Workbooks("RMT v8.0.2 - Huawei V1.2.xlsm").Activate
Workbooks("RMT v8.0.2 - Huawei V1.2.xlsm").Sheets("Input").Activate
Set sht = Workbooks("RMT v8.0.2 - Huawei V1.2.xlsm").Worksheets("Input")
Set sht1 = Workbooks("RMT v8.0.2 - Huawei V1.2_OI-408866.xlsb").Worksheets("MUForecasts")
Workbooks("RMT v8.0.2 - Huawei V1.2_OI-408866.xlsb").Activate
Workbooks("RMT v8.0.2 - Huawei V1.2_OI-408866.xlsb").Sheets("MUForecasts").Activate
n = sht1.Range("B" & Rows.Count).End(xlUp).Row
m = sht.Range("B" & Rows.Count).End(xlUp).Row
For i = 13 To m
For k = 3 To n
Debug.Print i, k
FGroup = sht.Range("H" & i)
PSkills = sht1.Range("R" & k)
RegCoun = sht.Range("L" & i)
WrCoun = sht1.Range("P" & k)
MRCode = sht.Range("X" & i)
RCode = sht1.Range("Q" & k)
If FGroup = PSkills Then
If RegCoun = WrCoun Then
If MRCode = RCode Then
sht.Cells(i, 2).Copy
sht1.Cells(k, 27).Select
Selection.PasteSpecial Paste:=xlPasteValues
End If
End If
End If
Next k
Next i
'wbk.Close
Set wbk = Nothing
Set sht = Nothing
Set sht1 = Nothing
Application.DisplayAlerts = True
End Sub