Sometimes Excel wants me to out "@" in front of UDF calls

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,532
Office Version
  1. 365
Platform
  1. Windows
I have two UDFs in the same code module called from the same sheet in a .xlsm book. For one, Excel requires an @ sign in front of the function name. Otherwise, it returns a #Value error. For the other, it will run it with or without the @ sign.

Can someone explain?

Thanks
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
That usually means your function is relying on implicit intersection to determine what to return: Implicit intersection operator: @
Thanks for that link. I did a little experimenting, but I still can't figure it out.

Using this test UDF:

VBA Code:
'Test implicit intersection operator (@)
Function testIIO(p1)
testIIO = p1 + 1
End Function

I ran these tests:

1599049530419.png


I understand why D6 fails, but why does D8?
 
Upvote 0
Ooops. I forgot to say that ColC is a named range assigned to $C:$C.

Here's a more complete set of examples:

1599050862461.png
 
Upvote 0
It’s implicit intersection (best avoided IMO) whereby Excel decides that you meant to refer to the item in the same row, not the entire column.
 
Upvote 0
It’s implicit intersection (best avoided IMO) whereby Excel decides that you meant to refer to the item in the same row, not the entire column.
Right, but why do D8 & D12 fail? They are right out of the examples:

=@INDEX(A1:A10,B1)
=@OFFSET(A1:A2,1,1)
 
Upvote 0
The @ needs to be in front of the part that requires implicit intersection. Your UDF doesn’t return an array, so it doesn’t need the @ but implicit intersection is required for the UDF to be passed just one cell, which is the only way it works (as you can’t use +1 on a multi-cell range), so you need the @ in front of the range name.
 
Upvote 0
Solution
The @ needs to be in front of the part that requires implicit intersection. Your UDF doesn’t return an array, so it doesn’t need the @ but implicit intersection is required for the UDF to be passed just one cell, which is the only way it works (as you can’t use +1 on a multi-cell range), so you need the @ in front of the range name.
So the @ on a parameter controls what get passed and the @ on the function name controls what gets returned?

And an extraneous @ is just ignored?
 
Upvote 0
I'm not sure about that last bit, to be honest. I wouldn't recommend just putting @ on everything for example.
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,731
Members
449,093
Latest member
Mnur

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