If you put the function in a worksheet module you will get the #Name error.
Press Alt+F11 to open the VBE and insert a new module by clicking INSERT in
the menu and selecting MODULE. Double click on the Sheet# icon under the
Microsoft Excel Objects folder in the VBA Project Explorer window, cut the
formula and paste it into the new module.
Add the following line under the Dim statement:
Application.Volatile
This will force the formula to recalc whenever the worksheet recalcs or you
press F9