-1

It's not that I don't know WHAT exactly is going wrong but it's the not knowing WHY it's going wrong thats making me lose my mind.

When writing any function in VBA with a name that has less than 4 characters and ends with a number, eq:

public function fun1(variable) or public function fn1(variable)

And then using that function in an excell cell will always give a #ref error.example

In the example a simple function for changing casing.

Is there someone who could relieve me from this dark place i'm currently in of not knowing what is going wrong.

C-M
  • 201
  • 2
  • 4
  • Please set the title of your question to something meaningfull. "Losing my mind" isn't a useful description of the problem. Always keep in mind that someone with a similar problem could find an answer on SO without raising a new question – FunThomas Nov 13 '20 at 11:43
  • Your function name can be interpreted as a valid cell reference on the excel worksheet. Hence your error. Note that this will also occur with valid cell references in either A1 or R1C1 notation. – Ron Rosenfeld Nov 13 '20 at 12:39

1 Answers1

2

The problem is that the names are ambiguous, fun1 and fn1 are both valid Range names. Change the name to something like MyFunction and it will work.

FunThomas
  • 23,043
  • 3
  • 18
  • 34