Hi, I wonder whether someone may be able to help me pelase.
From examples I've found, I'm trying to put together a short piece of code which performs the following:
- Looks at column B on the "Flexible Resources List" sheet, then
- Compare this to column D on the "All Data" sheet
- If a match is found, copy the associated value in column C on the "Flexible Resources List" sheet, and
- Paste into column O on the "All Data" sheet
This is the code that I've put together so far:
Sub Match()
Dim Rng As Range, Dn As Range, n As Long
Dim Dic As Object
With Sheets("Flexible Resources List")
Set Rng = .Range(.Range("B5"), .Range("B" & Rows.count).End(xlUp))
End With
Set Dic = CreateObject("scripting.dictionary")
Dic.CompareMode = vbTextCompare
For Each Dn In Rng
Set Dic(Dn.Value) = Dn
Next
With Sheets("All Data")
Set Rng = .Range(.Range("D5"), .Range("D" & Rows.count).End(xlUp))
End With
For Each Dn In Rng
If Dic.exists(Dn.Value) Then
Dn.Offset(, 1) = Dic.Item(Dn.Value).Offset(, 0 + 1)
Dn.Offset(, 3) = Dic.Item(Dn.Value).Offset(, 3 + 10)
End If
Next Dn
End Sub
I can get the compare and match function working and the correct information is copied from the "Flexible Resources List" sheet, but the value pastes into column E, rather than column O on the "All data" sheet.
I just wondered whether someone could possibly look at this please and let me know where I'm going wrong.
Many thanks and kind regards
Bookmarks