標題:
[發問]
請教:加速方法
[打印本頁]
作者:
198188
時間:
4 小時前
標題:
請教:加速方法
Sub Copy_Rack_Item()
Dim Brr, Arr, i&, n&, Q&, T$, S$, MyPath$, xFile$, xBook As Workbook, Re
Worksheets("Rack").Range("A2:O65600").Delete
Worksheets("Item").Range("A2:O65600").Delete
n = 2
T = Worksheets("Inv").Range("M1")
Application.ScreenUpdating = False
MyPath = "S:\EXPORT SHIPMENT\"
xFile = "Delivery Note Input Template.xlsx"
On Error Resume Next
Set xBook = Workbooks(xFile)
If xBook Is Nothing Then
Set xBook = Workbooks.Open(MyPath & xFile, , True, , "")
Re = True: ThisWorkbook.Activate
End If
On Error GoTo 0
Brr = xBook.Sheets("Rack").UsedRange
For i = 2 To UBound(Brr)
If xBook.Sheets("Rack").Cells(i, 11) = T Then
xBook.Sheets("Rack").Rows(i).Copy Destination:=Worksheets("Rack").Rows(n)
n = n + 1
End If
Next i
Q = 2
S = Worksheets("Rack").Range("A2")
Arr = xBook.Sheets("Item").UsedRange
For i = 2 To UBound(Arr)
If xBook.Sheets("Item").Cells(i, 1) = S Then
xBook.Sheets("Item").Rows(i).Copy Destination:=Worksheets("Item").Rows(Q)
Q = Q + 1
End If
Next i
12: If Re = True Then xBook.Close 0
End Sub
複製代碼
有兩個Excel,
本檔,Inv 表 M1儲存格 是 Invoice no
本檔,Rack 表 複製目的地 Row 2 開始
本檔,Item 表 複製目的地 Row 2 開始
來源檔 Delivery Note Input Template.xlsx
本檔,Rack 表 K 欄是 Invoice No, A 欄是 Work Order No
本檔,Item 表 A 欄是 Work Order No
如果來源檔Rack 表 K 欄 的 Invoice No 等於 本檔Inv 表 M1儲存格 是 Invoice no
複製 來源檔 Rack 表該欄到 本檔Rack 表 複製目的地 Row 2 開始往下
如果來源檔 Item 表 A 欄是 Work Order No 等於 本檔Rack 表A 欄是 Work Order No
複製 來源檔 Item 表 該欄到 本檔 Item 表 複製目的地 Row 2 開始往下
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)