![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Sutton Coldfield
Posts: 1,143
|
I have the following UDF code in VB
Function SpecialInterest(account, balance) 'this looks up the relevant special rate from the extract 'and works out the daily interest P&L contribution Rate = WorksheetFunction.VLookup(account, Special_Table, 18, False) SpecialInterest = (balance * (Rate / -100)) / 365 End Function I getting the following error msg 'Function call on LHS of assignment must return variant or object' The data i'm lookin up is in col 18 of special_table so what's the problem...? Can anyone shed any light on this for me please... Will. |
|
|
|
|
|
#2 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
as it is expecting the proper function call You will need to explicitly define rate eg Dim Rate Good practice NOT to use excel function names as your Definitions eg MyRate instead of Rate, MyCell instead of Cell etc. So your code should be Option Explicit Function SpecialInterest(account, balance) Dim Rate 'this looks up the relevant special rate from the extract 'and works out the daily interest P&L contribution Rate = WorksheetFunction.VLookup(account, Range("Special_Table"), 18, False) SpecialInterest = (balance * (Rate / -100)) / 365 End Function Note: Option explicit Look up online help for this...it will help you in capturing errors in syntax decalrations. |
|
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Location: Sutton Coldfield
Posts: 1,143
|
Thanks Ivan - works a treat now.
Will :grin |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|