Hi white_flag,
You can try also these examples:
' Original formula: =VLOOKUP(I5;INDIRECT(LOOKUP(LEFT(I5;1);{"R";"F"};{"Rockwool";"Foamglass"}));2)
' Warning1: approximate match is chosen in your VLOOKUP formula because the last argument is omitted
' Warning2: LOOKUP returs "Foamglass" for I5 values equal to "S","T","U","V"... and so on
' Write array formula
Sub WriteArrayFormulla1()
ActiveCell.FormulaArray = "=VLOOKUP(I5,INDIRECT(LOOKUP(LEFT(I5,1),{""R"",""F""},{""Rockwool"",""Foamglass""})),2)"
End Sub
' Write array formula, using value from 3 rows down to the active cell
Sub WriteArrayFormulla2()
Dim a As String
With ActiveCell
a = .Offset(3, 0).Address(1, 0)
.FormulaArray = "=VLOOKUP(" & a & ",INDIRECT(LOOKUP(LEFT(" & a & ",1),{""R"",""F""},{""Rockwool"",""Foamglass""})),2)"
End With
End Sub
' Evaluate method, issues of both Warnings are fixed
Sub VbaEvaluate()
Dim a$, b$
With ActiveCell.Offset(3, 0)
a = .Address
Select Case UCase(Left(.Value, 1))
Case "R": b = "Rockwool"
Case "F": b = "Foamglass"
Case Else: MsgBox a & vbTab & .Value, , "Not found": Exit Sub
End Select
MsgBox Evaluate("VLOOKUP(" & a & "," & b & ",2,0)")
End With
End Sub
Regards,
Vladimir