create function and apply it in datavalidation formula box

hamed_

New Member
Joined
Sep 7, 2020
Messages
9
Office Version
  1. 2007
Platform
  1. Windows
hi everybody ,,,
i have created a function named check_ punctuation like this :
VBA Code:
Function check_punctuation(my_str As String) As Boolean
Dim asci_code
Dim str_temp
For i = 1 To Len(my_str)
asci_code = Asc(Mid(my_str, i, 1))
Select Case asci_code
Case 32 To 47
check_punctuation = True
Case 123 To 126
check_punctuation = True
Case 91 To 96
check_punctuation = True
Case 61
check_punctuation = True
Case 64
check_punctuation = True
Case Else
check_punctuation = False

End Select

Next

End Function
function_code.png


this function work fine and return true or false , but whenever i use it in DataValidation , Custom box excel message alert for every data entry.
use in cell.png

validationbox.png

example.png

plz helpppppppp
with best wishes for all my friends ...
 
Refined code that doesn't crash.
VBA Code:
Function IS_Alphabet(mystr As String) As Boolean
Dim i As Long
For i = 1 To Len(mystr)
    Select Case Asc(Mid(mystr, i, 1))
        Case 32 To 47, 58, 59, 61, 64, 91 To 96, 123 To 126
            Exit Function
    End Select
Next
    IS_Alphabet = True
End Function

Follow steps in post #16, but change the validation formula in step 6 to

=NM_IS_ALPHABET

Make sure that the data validation 'Ignore blank' checkbox is not checked.

I have tested this and it does work.

Refined code that doesn't crash.
VBA Code:
Function IS_Alphabet(mystr As String) As Boolean
Dim i As Long
For i = 1 To Len(mystr)
    Select Case Asc(Mid(mystr, i, 1))
        Case 32 To 47, 58, 59, 61, 64, 91 To 96, 123 To 126
            Exit Function
    End Select
Next
    IS_Alphabet = True
End Function

Follow steps in post #16, but change the validation formula in step 6 to

=NM_IS_ALPHABET

Make sure that the data validation 'Ignore blank' checkbox is not checked.

I have tested this and it does work.

Hoooooera.
Finally , it's Done...
thanks a lot brother
Your refined function worked.
As I said in previous posts, the problem is in how we define function.
So , I must define other functions base on your function.
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I'm not entirely sure why Mine worked and yours didn't, I've removed some lines that were not needed but not made any significant changes.
The only thing that I can see might have been the cause was using 'Option Compare Text' which I removed. I didn't try your code without it so it it could be worth trying that before re-writing everything else.
 
Upvote 0

Forum statistics

Threads
1,216,499
Messages
6,131,010
Members
449,613
Latest member
MedDash99

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top