Function call error

Crafty64

Board Regular
Joined
Aug 26, 2010
Messages
55
Hi, I have a function which returns the following error and I'm not sure why:

"Function call on left hand side of assignment must return variant or object"

Any suggestions to fix it?

The function is a copy of an existing one that works but I change the name of the function...
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Sure:

Function PortDefaultTime01(X As Double) As Integer
'returns default time from xation of -LN(1-U)for Portugal
If X <= Range("Port1yr") Then PortDefaultTime = 1
If X > Range("Port1yr") And X <= Range("Port2yr") Then PortDefaultTime = 2
If X > Range("Port2yr") And X <= Range("Port3yr") Then PortDefaultTime = 3
If X > Range("Port3yr") And X <= Range("Port4yr") Then PortDefaultTime = 4
If X > Range("Port4yr") And X <= Range("Port5yr") Then PortDefaultTime = 5
If X > Range("Port5yr") Then PortDefaultTime = 0
 
Upvote 0
Shouldn't it be

If X <= Range("Port1yr") Then PortDefaultTime01 = 1
 
Upvote 0
when you renamed the PortDefaultTime01, you didn't rename the return variables in the function.

You'll need to name PortDefaultTime to PortDefaultTime01.

That'll fix it.

On a side note, I personally would have a temp variable in there that you use and then at the very end assign PortDefaultTime01 to the value of the temp variable. Just my preference, though.
 
Upvote 0
when you renamed the PortDefaultTime01, you didn't rename the return variables in the function.

You'll need to name PortDefaultTime to PortDefaultTime01.

That'll fix it.

On a side note, I personally would have a temp variable in there that you use and then at the very end assign PortDefaultTime01 to the value of the temp variable. Just my preference, though.

Guess I'm a little slow today!
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top