I have a the following on my worksheet:
- A cell that shows a currency [in
A1] - A range of cells (two columns, one for the currency, and the other for a corresponding commission percentage) [defined as/named
RANGE, and scoped to the worksheet] - A cell that [is trying] to determine the calculated commission percentage based on
A1andRANGE
I then have a VBA function called Calculate, as follows:
Function Calculate(LookupValue As Double, LookupRange As Range) As Double
Calculate = [VLOOKUP(LookupValue, LookupRange, 2)]
End Function
The cell that determines the percentage has the following:
=Calculate(A1, RANGE)
Problem is that the cell just returns #VALUE!...
Any idea what I could be doing wrong?
I have tried several things like type-hinting to Range(), passing LookupRange.Value2 to VLOOKUP, etc, none of which worked.
I have also tried to debug, noting that LookupRange does actually contain the range required in Value2, which is is why I tried to pass it to the function.
Side Note: The function and layout mentioned above is just a dummy - the actual function is somewhat more complex as it relies on negotiated rates, monthly margins, etc. This is why I'm using VBA in the first place. I know that I'm doing something wrong with the lookup, as it is the only thing that seems to be failing within the function - everything else corresponds and calculates.
[]which returns a range object. There is no range called whatever your lookup returns. You want to return the value:Calculate =Application.WorksheetFunction.VLOOKUP(LookupValue, LookupRange, 2)`