alexaronson
Active Member
- Joined
- Sep 30, 2005
- Messages
- 314
I need some help speeding up this macro. The area that is slowing me down is my For loop with the vlookup. lastRow of the loop is ~45,000 iterations. Normally, it takes only a minute to process in past macro uses. However, it is taking 15 minutes to complete which is just not right.
Here is what I have so far.
Here is what I have so far.
Code:
Sub UpdateCapacity()
Application.ScreenUpdating = False
Dim wbUC As Workbook 'this is the variable to keep this file's name
Dim wsDMDD As Worksheet 'this is hte variable to store the demand data worksheet
Dim wsInvD As Worksheet ' this is the variable to store the name of the Inventory data worksheet name
Dim i As Long 'this is row counter tracker
Dim j As Integer 'this is a column counter tracker
Dim lastRow As Long 'this is to track the column data
Dim lastRow2 As Long 'this is to track the column data while lastRow is in use
Dim a As Integer 'this variable is spare count variable
Dim lastColumn As Integer 'used to find the last column of data in the roll forward report
Dim strColName As Variant 'used to rename the column variable that lastColumn returns
Dim x As Long 'used to temporarily hold the looked out value
Set wbUC = ThisWorkbook
Set wsDMDD = wbUC.Worksheets("Dump Data Demand")
Set wsInvD = wbUC.Worksheets("Free Stock")
'Match Free Stock to Demand
i = 12
lastRow = wsDMDD.Range(strColName & Rows.Count).End(xlUp).Row
lastRow2 = wsInvD.Range("B" & Rows.Count).End(xlUp).Row
For i = i To lastRow
On Error Resume Next
x = WorksheetFunction.VLookup(wsDMDD.Cells(i, 3), wsInvD.Range("A1:B" & lastRow2), 2, False)
If Err.Number = 0 Then wsDMDD.Cells(i, lastColumn + 1) = x
x = 0
Next
Application.ScreenUpdating = True
End Sub