Hi
What I'm trying to do is loop through each open workbook and check if the value of D4 is similar to a value within range "A2:A17" within my workbook "AHT", the worksheet also called "AHT".
If true, then to copy the value of "I9" from the matching workbook and paste the value in my AHT workbook, column E (same row as the match).
My example,
- In workbook "AHT", Cell A5 has "Firstname Surname" (within range "A2:A17"),
- So loop through each open workbook and check if D4 within each workbook also has "Firstname Surname"
- If it does, then to copy the value of cell I9 from this matching workbook, and, paste the value in E5 within workbook "AHT".
- The contents of D4 in each workbook to loop through, will be like "1234 - Firstname Surname" so it can't be looking for an exact match.
The code I've tried so far is below, but I get run-time error 9, subscript out of range.
Any help would be really be appreciated.
Thank you
What I'm trying to do is loop through each open workbook and check if the value of D4 is similar to a value within range "A2:A17" within my workbook "AHT", the worksheet also called "AHT".
If true, then to copy the value of "I9" from the matching workbook and paste the value in my AHT workbook, column E (same row as the match).
My example,
- In workbook "AHT", Cell A5 has "Firstname Surname" (within range "A2:A17"),
- So loop through each open workbook and check if D4 within each workbook also has "Firstname Surname"
- If it does, then to copy the value of cell I9 from this matching workbook, and, paste the value in E5 within workbook "AHT".
- The contents of D4 in each workbook to loop through, will be like "1234 - Firstname Surname" so it can't be looking for an exact match.
The code I've tried so far is below, but I get run-time error 9, subscript out of range.
VBA Code:
For Each WB In Workbooks
If WB.Name <> "AHT" And WB.Name <> "0005*" Then
With WB.Sheets(1)
If Range("D4") Like Workbooks("AHT").Worksheets("AHT").Range("A2:A17") Then
.Range("I9").Copy
Workbooks("AHT").Worksheets("AHT").Offset(, 5).PasteSpecial xlPasteValues
End If
End With
End If
Next
Any help would be really be appreciated.
Thank you