5

I have a user defined function that i want to use in a custom data validation. My function is working properly but when i use it in data validation, it's every time in error...

There is the code:

Public Function AlphaNumeric(pValue) As Boolean
    Dim LPos As Integer
    Dim LChar As String
    Dim LValid_Values As String

    'Start at first character in value
    LPos = 1

    'Test each character in value
    While LPos <= Len(pValue)
        'Single character in value
        LChar = Mid(pValue, LPos, 1)

        'If character is not alphanumeric, return FALSE
        If InStr(REFALPHACHAR, LChar) = 0 Then
           AlphaNumeric = False
           Exit Function
        End If

        'Increment counter
        LPos = LPos + 1
   Wend

   'Value is alphanumeric, return TRUE
   AlphaNumeric = True
End Function

And the setting of my data validation:

Data validation setting

1
  • Please explain the error in more detail. On what line is crashing? What's the error message? Commented Apr 7, 2016 at 8:25

1 Answer 1

7

You cannot use a UDF directly in data validation. You can however use it via a named formula.

Select A1, then in Name Manager define a name called IsAlphaNum whose refersto is:

=alphanumeric(A1)

(Note: no $ signs in the cell reference)

Then in your data validation use =IsAlphaNum and uncheck the 'Ignorer si vide' option.

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

2 Comments

How i can improve this solution to use it on an entire table column?
It will work on the entire column. You use the same validation for each cell in the column.

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.