Guinaba
Board Regular
- Joined
- Sep 19, 2018
- Messages
- 235
- Office Version
- 2016
- Platform
- Windows
Hi guys,
I'm trying to use vlookup within array to make the code runs faster, in the code below the .Cells(ii, 1).Formula with vlookup is working ok, however the other two lines don't. Any suggestion? These two lines are doing the same thing, just trying different approaches.
.Cells(ii, 1).value = Application.VLookup(ArrCalc(ii, 1), ArrVlkup1, 2, False)
ArrResult1(ii) = Application.VLookup(ArrCalc(ii, 1), ArrVlkup1, 2, False)
I'm trying to use vlookup within array to make the code runs faster, in the code below the .Cells(ii, 1).Formula with vlookup is working ok, however the other two lines don't. Any suggestion? These two lines are doing the same thing, just trying different approaches.
.Cells(ii, 1).value = Application.VLookup(ArrCalc(ii, 1), ArrVlkup1, 2, False)
ArrResult1(ii) = Application.VLookup(ArrCalc(ii, 1), ArrVlkup1, 2, False)
VBA Code:
Sub TPRP_Refresh()
Application.ScreenUpdating = False
'Loop to calculate the formulas
Dim RangeCalc As Range
Set RangeCalc = Sheets("TPRP").Range("A1").CurrentRegion
Dim ArrCalc() As Variant
Dim RangeVlkup1 As Range
Set RangeVlkup1 = Sheets("criteria").Range("A2").CurrentRegion
Dim ArrVlkup1() As Variant, ArrResult(500) As Variant
ArrVlkup1 = RangeVlkup1
ArrCalc = RangeCalc
Dim ii As Long
For ii = 5 To UBound(ArrCalc)
.Cells(ii, 1).Formula = "VLOOKUP(H" & ii & ",criteria!A:B,2,FALSE))" ‘This method works
.Cells(ii, 1).value = Application.VLookup(ArrCalc(ii, 1), ArrVlkup1, 2, False) ‘This method doesn’t work
ArrResult1(ii) = Application.VLookup(ArrCalc(ii, 1), ArrVlkup1, 2, False) ‘This method doesn’t work
Next ii
ii = ii + 1
End With
Application.ScreenUpdating = True
End sub