Dim mDic As Object
Dim mWk1 As Workbook
Dim mSht1 As Worksheet
Dim mRng As Range
Dim E As Range
Set mDic = CreateObject("Scripting.Dictionary")
Set mWk1 = Workbooks("總表")
With mWk1
Set mSht1 = Worksheets(1)
With mSht1
Set mRng = .Range("b2:b" & .[a65536].End(xlUp).Row)
End With
For Each E In mRng
If mDic.Exists(E.Value) = False Then
mDic(E.Value) = E.Offset(, 1).Value
End If
Next
End With
With Workbooks.Open(ThisWorkbook.Path & "\" & 123 & ".xls")
With Sheets(1)
For Each E In .Range(.[A2], .[A2].End(xlDown))
E.Offset(, 1) = mDic(E.Value)
Next
End With
.Close
End With
End Sub作者: GBKEE 時間: 2011-9-1 06:59
回復 2#dechiuan999
注意With裡的敘述要加 .
''''''''''''''''''''''''''''''''''''
With
Set mWk1 = Workbooks("總表")
With mWk1
Set mSht1 = .Worksheets(1)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
With Workbooks.Open(ThisWorkbook.Path & "\" & 123 & ".xls")
With .Sheets(1)作者: dechiuan999 時間: 2011-9-1 09:46
Dim mDic As Object
Dim mWk1 As Workbook
Dim mSht1 As Worksheet
Dim mRng As Range
Dim E As Range
Set mDic = CreateObject("Scripting.Dictionary")
Set mWk1 = Workbooks("123")
With mWk1
Set mSht1 = .Worksheets(1)
With mSht1
Set mRng = .Range("a2:a" & .[a65536].End(xlUp).Row)
End With
For Each E In mRng
If mDic.Exists(E.Value) = False Then
mDic(E.Value) = E.Offset(, 1).Value
End If
Next
End With
With Workbooks.Open(ThisWorkbook.Path & "\" & "總表" & ".xls")