1

I have this function in a module in my VBE, but when I try to access it in my userforms, I get an error because it cannot be detected by VBE: Error

This is the Col_Letter function:

Function Col_Letter(lngCol As Long) As String
    Dim vArr
    vArr = Split(Cells(1, lngCol).Address(True, False), "$")
    Col_Letter = vArr(0)
End Function

I also tried adding Public:

Public Function Col_Letter(lngCol As Long) As String
    Dim vArr
    vArr = Split(Cells(1, lngCol).Address(True, False), "$")
    Col_Letter = vArr(0)
End Function
2
  • 1
    Your module is named Col_Letter as well. Change the name of the module and it would work. Commented Jun 26, 2018 at 9:26
  • I always prefix module names with 'm', class modules with 'cls'. Now I know why 8-) Commented Jun 26, 2018 at 9:33

1 Answer 1

3

Naming a module with the same name as a public funciton is quite a bad idea. Change the name of the Col_Letter module or the name of the function.

Sign up to request clarification or add additional context in comments.

4 Comments

Right. I've been really confused as to why it's not working. Thanks
@MarcSantos - you are welcome. Making the function public was a good first step.
@MarcSantos Something that I find helps is to use a type-declaration prefix to objects and variable (e.g. lng_Users for a Long variable, frm_Users for a UserForm, mod_Users for a Module, etc) - it also makes it much easier when you review code at a later date to work out what everything is/does
@Chronocidal - this is a great article by the creator of StackOverflow, which goes 100% against this practice. Read it, it may change your coding style forever - joelonsoftware.com/2005/05/11/making-wrong-code-look-wrong

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.