TropicalMagic
New Member
- Joined
- Jun 19, 2021
- Messages
- 47
- Office Version
- 365
- Platform
- Windows
Hi all,
I’m trying to –
Here is my code:
Many thanks in advance!
I’m trying to –
- Compare Column G from Workbook 1, starting from row 2, to only the first 10 characters in Column A, starting from row 9, from Workbook 2 for matching values
- If there are matching values, copy only the last 3 characters in Column A from Workbook 2 to Column F from Workbook 1
Here is my code:
VBA Code:
Dim Range1 As Range, Range2 As Range, Rng1 As Range, Rng2 As Range
Dim i As Long
Set Range1 = Workbook1.Sheet(1).Range("G9:G" & LASTROW1)
Set Range2 = Workbook2.Sheet(1).Range("A2:A" & LASTROW2)
For i = 9 to LASTROW1
For Each Rng1 in Range1
For Each Rng2 In Range2
If Rng1.Value = Left(Rng2.Value, 10) Then
Right(Rng2.Value, 3).Copy
Workbook1.Sheet(1).Range("F" & i).PasteSpecial
End If
Next
Next
Next
Many thanks in advance!