I have 2 worksheets within the same workbook. I'm trying to copy a range of cells from mFS and paste them into mWD where a key exists on both sheets. I didn't want to add 24 VLOOKUP formulas with VBA, so I thought I would try my hand at a scripting dictionary (which may not be the best route either). Here is the code that I have now, which works, but I'm unsure how to copy the range of cells over instead of just 1 cell at a time. Thoughts?
VBA Code:
Sub MergeData()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim m As Workbook
Dim mWD, mFS As Worksheet
Dim WDLR, FSLR As Long
Dim C1 As Range
Dim Dic As Object
Set m = ThisWorkbook
Set mWD = m.Sheets("Working_Data")
Set mFS = m.Sheets("From_SPARC")
WDLR = mWD.Range("A" & Rows.Count).End(xlUp).Row
FSLR = mFS.Range("B" & Rows.Count).End(xlUp).Row
mFS.Range("A2:A" & FSLR).Formula = "=RC[1] & "" | "" & RC[3] & "" | "" & RC[4] & "" | "" & RC[5]"
mWD.Range("M2:M" & WDLR).Formula = "=RC[-12] & "" | "" & RC[-8] & "" | "" & RC[-9] & "" | "" & RC[-6]"
Set Dic = CreateObject("scripting.dictionary")
With mFS
For Each C1 In .Range("A2", .Range("A" & Rows.Count).End(xlUp))
Dic(C1.Value) = C1.Offset(, 6).Value
Next C1
End With
With mWD
For Each C1 In .Range("M2", .Range("A" & Rows.Count).End(xlUp))
If Dic.exists(C1.Value) Then C1.Offset(, 1).Value = Dic(C1.Value)
Next C1
End With
Application.DisplayAlerts = False
Application.ScreenUpdating = False
End Sub