Share via

Custom function returns #NAME?

Anonymous
2010-07-28T12:27:40+00:00

I created the following function with this code to find the first numeric charactor in a string in a cell. Cell E3 contains the string to be checked. When I enter the formula =Pos_nonalpha(E3) it returns #NAME?. What am I doing wrong?

Thanks,

JCM

Function Pos_nonalpha(cell) As Long Dim i As Long For i = 1 To Len(cell) Dim Number Select Case Asc(Mid(cell, i, 1)) Case 0 To 64, 91 To 96, 123 To 191 Pos_nonalpha = i Exit Function End Select Next i Pos_nonalpha = 0End Function

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2010-07-28T14:33:22+00:00

Maybe you don't have macros enabled?


Bill Manville. Excel MVP, Oxford, England. www.manville.org.uk

Was this answer helpful?

0 comments No comments

10 additional answers

Sort by: Most helpful
  1. Anonymous
    2010-07-28T12:54:00+00:00

    I changed "Cell" to "Cel" but still getting #NAME?. I tried entering in another cell, same result :(

    Thanks,

    JCM

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2010-07-28T12:44:11+00:00

    Try not using "Cell" as your variable to pass as it's a reserved name in VBA

    Function Pos_nonalpha(cel) As Long 

    And amend any references to "Cell" in your UDF

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2010-07-28T12:38:15+00:00

    Bill,

    After I hit Alt & F11, when I click Module 1 in the project tree on the left, I see the code. When  I start to type the formula, Excel seems to recognize it as it appears in the function dropdown list.

    Thanks,

    JCM

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2010-07-28T12:32:44+00:00

    Make sure the function is in a standard module, not a class module (such as ThisWorkbook or Sheet1)


    Bill Manville. Excel MVP, Oxford, England. www.manville.org.uk

    Was this answer helpful?

    0 comments No comments