Hi all, I have made a little VBA to lookup value from another sheet but it is very slow already loop thru row. How can I speed it up and also make it loop through row?
VBA Code:
Sub filldata()
'find rollupcode from data abailability tab
'Speed up VBA, turning off other components
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
'Set Variable
Dim wb1 As Workbook, wb2 As Workbook, ws1 As Worksheet, ws2 As Worksheet
'Market Data File
Set wb1 = Workbooks("checking_v0.2.xlsx")
Set ws1 = wb1.Worksheets("data availability check")
Set ws3 = wb1.Worksheets("peer group market data")
'Template
Set wb2 = Workbooks("Benchmarking.xlsm")
Set ws2 = wb2.Worksheets("MarketData")
'For Vlookup Roll up Grade
ws1.Activate
Set fulljobcode = ws1.Range("J2", Range("J" & Rows.Count).End(xlUp))
Set rollupcode = ws1.Range("K2", Range("K" & Rows.Count).End(xlUp))
Set vlookuparray = ws1.Range("J:K")
With ws2
wb2.Activate
lastRow = Range("B" & Rows.Count).End(xlUp).row
For r = 3 To lastRow
Cells(r, 2) = Application.VLookup(Cells(r, 1), vlookuparray, 2, False)
Next r
End With
'For Index Match Market Data
Set col_array = ws3.Range("A1:PN1")
Set row_array = ws3.Range("A2:A14365")
index_array = ws3.Range("A1:PN14365")
lastRow = ws2.Range("B" & Rows.Count).End(xlUp).row
'lastCol = ws2.Range("C2").End(xlToRight).col
With ws2
For i = 3 To lastRow
On Error Resume Next
Cells(i, 3) = Application.Index(index_array, _
Application.Match(Cells(i, 2), row_array, 0), Application.Match(Cells(1, 3), col_array, 0))
Next i
'Turn things back on
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
Application.ScreenUpdating = True
End With
End Sub