我有兩筆資料要比對,可是我要比較的欄位資料並不完全相同,例如,在A工作表湖人隊以Lakers表示,但在B工作表湖人隊是以LAL表示
因此我想利用vlookup的方式間接比較資料
以下是我的VBA程式碼,可是執行上卻有錯誤,請問我這樣使用對嗎?可以這樣用嗎?有其他方法能達成我的目的嗎?謝謝
Sub aa()
Dim mDic As Object
Dim mWk1 As Workbook
Dim mSht1 As Worksheet
Dim mRng As Range
Dim vRng As Range
Dim E As Range
Set mDic = CreateObject("Scripting.Dictionary")
Set mWk1 = Workbooks("Mapping1")
With mWk1
Set mSht1 = .Worksheets(2)
With mSht1
Set mRng = .Range("b2:b" & .[b65536].End(xlUp).Row)
End With
Set vRng = .Worksheets(3).Range("a2:b11")
For Each E In mRng
If mDic.Exists(E.Value) = False Then
mDic(Application.WorksheetFunction.vlookup(E.Value, vRng, 2, 0) & Application.WorksheetFunction.vlookup(E.Offset(, 2).Value, vRng, 2, 0)) = E.Offset(, 4).Resize(,2)
End If
Next
End With