Struggling to figure out how to write the following in Excel VBA:
=LOOKUP(2,1/(A:A=K8),F:F)
My current attempt looks as such:
Application.lookup(2, [1 / (dates = (lookupDate + lookupModifier))], balances))
When I break out to just the array formula I get a #VALUE error, as part of the lookup I get #NAME.
The original formula was taken from a site that didn't particularly explain what the central parameter does, while I understand what it does I am unsure of the correct terminology for it so apologies for that.
The full formula for reference:
Option Explicit
Public Function GetWeekEndBalanceFromStatement(lookupDate As Double, dates As Range, balances As Range) As Variant
Dim lookupModifier As Integer
Do While IsError(Application.lookup(2, [1 / (dates = (lookupDate + lookupModifier))], balances)) And lookupModifier > -7
lookupModifier = lookupModifier - 1
Loop
GetWeekEndBalanceFromStatement = Application.lookup(2, [1 / (dates = (lookupDate + lookupModifier))], balances)
End Function
[...]is a shortcut toEvalutewhere what's between the brackets is what you would type into the Exel formula bar. In this casedatesetc are parameters to the function so are unknown to Excel. Try usingdates.Worksheet.Evaluate(...)and build the formula withdates.Addressetc