Excel 2010 ships with some functions that contain a period in their name. For example STDEV.S
and PERCENTILE.EXC
Is it possible to assign a name to my own function with a name such as PERCENTILE.CUSTOM
using VBA?
For example, I would like to reference the following function using the formula =NAME.SUFFIX()
Option Explicit
Function NAMEdotSUFFIX() As Variant
NAMEdotSUFFIX = 42
End Function
As @SiddharthRout already suggested, external libraries have fewer restrictions than VBA when it comes to declaring function names, so periods are permitted in external names.
Despite the MSDN documentation, it is possible to use some special characters in VBA identifiers, including UDFs. The special characters can even be the first/only character in the identifier. The special characters will vary in their availability, according to the code-page of the VBA project and VBE.
This is a perfectly valid VBA function:
And can be used in an Excel formula:
Likewise, this gem of a function uses a non-breaking space as the function name:
But while the function with an NBSP is valid, sadly, it can't be used in an Excel formula.
It is possible to use:
BONUS HACK
Somebody forgot to tell the
Enum
team about the identifier rules. And while Enums can't be used in Excel formulas, you can use any character except a carriage return or square-brackets inside square brackets, as an enum name or member.This is perfectly valid VBA:
And the VBE pretty-printer turns it into this unparseable mess:
It is not possible from VBA. This MSDN article shows how to define a function in VBA, and specifically this article lays out the rules for element names.