For all intents and purposes you are really only concerned with the last number in column B, not specifically the last row. To do that in a worksheet formula you would use something like this array formula.
=MIN(IF(--LEFT(B1:INDEX(B:B, MATCH(1E+99,B:B )),5)=C1, B1:INDEX(B:B, MATCH(1E+99,B:B))))
That can translate into your VBA Evaluate method like the following.
Sub Evaluation_Formula()
Dim i As Long
With Worksheets("Sheet1")
i = .Evaluate("MIN(IF(--LEFT(B1:INDEX(B:B, MATCH(1E+99,B:B )),5)=C1, B1:INDEX(B:B, MATCH(1E+99,B:B))))")
.Range("F3").Value2 = i
End With
End Sub
The double unary (aka double-minus or --
) does the same job as multiplying the text result from the LEFT function by 1. There is no need to pass a zero-length string (e.g. ""
) in as the FALSE is sufficient for non-matches in the IF function. Since you are evaluating text into a formula, there is no need for the $
absolute markers.
Keep the .
in .Evaluate
or add the worksheet name to the cell references in the formula. Without it you run the risk of evaluating another worksheet's B1:B89 and C1 cells if Sheet1 does not hold the workbook's ActiveSheet property.