我要做的是在一张纸上搜索匹配的数据,然后在第二张纸中返回相应的值。 查看示例数据, 第一个表是仓库的历史使用数据,部分是Use-Date_Calc。 在第15行的第二个表中,我有每日日期范围,我想填充第一个表中的每日使用情况。 Please check the screen shot for sample data 我的代码非常慢。第一个表有超过17000行,第二个表有658个单日和4000行。 请快速帮助。谢谢期待 乔恩
Branch_ID Warehouse_ID Part_ID Part_Descr Unit_Cost Use_Date_System Use_Date_Calc Qty DayOfWeek CombinedSearchKey
ACT ACT001 D0001 12 11/11/2014 11/11/2014 1 2 ACT001D00012014.11.11
ACT ACT052 D0002 12 19/11/2014 19/11/2014 1 3 ACT001D00012014.11.11
ACT ACT052 D0003 12 6/08/2014 6/08/2014 1 3 ACT001D00012014.11.11
ACT ACT052 D0004 12 20/10/2014 20/10/2014 1 1 ACT001D00012014.11.11
ACT ACT052 D0005 12 27/01/2015 27/01/2015 3 2 ACT001D00012014.11.11
ACT ACT052 D0006 12 16/03/2015 16/03/2015 1 1 ACT001D00012014.11.11
??? ??? ??? ??? ??? ??? ??? ??? ??? ???
??? ??? ??? ??? ??? ??? ??? ??? ??? ???
31/07/2014 31/07/2014 31/07/2014 31/07/2014 31/07/2014 31/07/2014 31/07/2014 31/07/2014
6/07/2014 6/07/2014 6/07/2014 6/07/2014 13/07/2014 13/07/2014 13/07/2014 13/07/2014
2 3 4 5 1 2 3 4
2014.7.1 2014.7.2 2014.7.3 2014.7.4 2014.7.7 2014.7.8 2014.7.9 2014.7.10
Branch_ID Warehouse_ID Part_ID Part_Descr Unit_Cost 1/07/2014 2/07/2014 3/07/2014 4/07/2014 7/07/2014 8/07/2014 9/07/2014 10/07/2014 ACT ACT001 D0001#N / A#N / A#N / A#N / A#N / A#N / A#N / A#N / A ACT ACT052 D0002#N / A#N / A#N / A#N / A#N / A#N / A#N / A#N / A ACT ACT052 D0003#N / A#N / A#N / A#N / A#N / A#N / A#N / A#N / A ACT ACT052 D0004#N / A#N / A#N / A#N / A#N / A#N / A#N / A#N / A ACT ACT052 D0005#N / A#N / A#N / A#N / A#N / A#N / A#N / A#N / A ACT ACT052 D0006#N / A#N / A#N / A#N / A#N / A#N / A#N / A#N / A ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ???
Sub Assign_Formula_Aggr_Parts_Usage_Daily(Branch As String, Rng_Start As Range, Rng_End As Range)
Dim Rng As Range
Dim Cell As Range
Dim arrData() As Variant
Dim lRows As Long
Dim lCols As Long
Dim i As Long, j As Long
Dim bEvents As Boolean
Dim bAlerts As Boolean
Dim CalcMode As Long
Dim bScreen As Boolean
' save current settings
bEvents = Application.EnableEvents
bAlerts = Application.DisplayAlerts
CalcMode = Application.Calculation
bScreen = Application.ScreenUpdating
' disable events, alerts, automatic calculation & screen updating
With Application
.EnableEvents = False
.DisplayAlerts = False
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
Worksheets("PartsUsage_" & "Daily" & "_" & Branch).Activate
Set Rng = Range(Rng_Start, Rng_End)
If TypeName(Rng) <> "Range" Then Exit Sub
lRows = Rng.Rows.Count
lCols = Rng.Columns.Count
ReDim arrData(1 To lRows, 1 To lCols)
arrData = Rng.Value
For j = 1 To lCols
For i = 1 To lRows
arrData(i, j) = "=INDEX(PartsUsage!C8,MATCH(RC2&RC3&R6C,PartsUsage!C10,0),1)"
Next i
Next j
Rng.Value = arrData
Rng.Copy
Rng.PasteSpecial xlPasteValues
Application.CutCopyMode = False
Set Rng = Nothing
' restore previous settings
With Application
.EnableEvents = bEvents
.DisplayAlerts = bAlerts
.Calculation = CalcMode
.ScreenUpdating = bScreen
End With
End Sub