welshgasman
Well-known Member
- Joined
- May 25, 2013
- Messages
- 1,402
- Office Version
- 2019
- 2007
- Platform
- Windows
Hi all,
I am trying to created a UDF for a complicated (to me) calculation.
In the function I have
TxAmount is passed to the function. let's make it 22000 for this example
if I try ? WorksheetFunction.VLookup(TxAmount, Sheets("Lookup").Range("A2:E6"), 5, True) after setting TxAmount in the debug window, I get the correct result.
However when I try ? CalcFee(22000) I get
Run-time error 1004
Unable to get the Vlookup property of the worksheet function class
This is only the start of the code, but I am relying on picking up this value for further calculations?
What am I missing please?
TIA
I am trying to created a UDF for a complicated (to me) calculation.
In the function I have
Code:
Function CalcFee(TxAmount As Currency) As Currency
Dim iFeeType As Integer
'FeeType indicates whether a set value £200 or a %
iFeeType = WorksheetFunction.VLookup(TxAmount, Sheets("Lookup").Range("A2:E6"), 5, True)
If iFeeType = 3 Then
IFAFee = Sheets("Lookup").Range("D7").Value
Else
IFAFee = Round(TxAmount * Sheets("Lookup").Range("D7").Value, 2)
End If
End Function
TxAmount is passed to the function. let's make it 22000 for this example
if I try ? WorksheetFunction.VLookup(TxAmount, Sheets("Lookup").Range("A2:E6"), 5, True) after setting TxAmount in the debug window, I get the correct result.
However when I try ? CalcFee(22000) I get
Run-time error 1004
Unable to get the Vlookup property of the worksheet function class
This is only the start of the code, but I am relying on picking up this value for further calculations?
What am I missing please?
TIA