I'm writing a VBA function which I want to be publically available in other VBA modules within the same document, however I don't want it to be available as a UDF (User defined function).
If I use the public access modifier however my function is also be available as a UDF-formula that can be called from the cells within the workbook. I don't want this.
Is there an access modifier or other way that can help me obtain this "VBA only" behaviour?
Kind regards
Using Exit Sub Statement in VBA First, decide on which line you want to add the “Exit Sub”. After that, check the structure of the code that will get executed when you run the code. Next, enter the “Exit Sub”. In the end, it's better to have comment that describes why you are using the “Exit Sub” statement.
You cannot "call" a function. A function provides a result; you need to set some variable equal to your function. If you just need the code to run, and don't need it to provide you with a specific variable result, then make it a sub, and not a function.
A UDF cannot modify the formatting of a cell or workbook or move values around on a worksheet. Basically, UDF's enable you to create custom functions that act very similarly to the built-in functions that are included in every installation of Excel, such as SQRT, SUM, and MAX.
If you use Option Private Module
in the module in which the function appears, the function can be declared as Public
and used in any of your other modules within your VBA project, but won't be accessible by other applications or projects, including Excel itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With