Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default VALIDATION USING ALPHA-NUMERICS ONLY - NO SPECIAL CHARACTERS

Hi. Is there a simple validation formula that would restrict a cell
to alpha-numerics only and exclude all other characters? Thanks in
advance. :)

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default VALIDATION USING ALPHA-NUMERICS ONLY - NO SPECIAL CHARACTERS

for these entries entered as text:
is "False" an alphanumeric. Is "123" an alphanumeric? Is "1 Jan 2001" an
alpha numeric? Is anything preceded with a single quote an alphanumeric?
Is "%$#^" an alphanumeric?

Could you be more precise in your description of what an alpha numeric is in
your definition.

--
Regards,
Tom Ogilvy



"KLZA" wrote:

Hi. Is there a simple validation formula that would restrict a cell
to alpha-numerics only and exclude all other characters? Thanks in
advance. :)


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default VALIDATION USING ALPHA-NUMERICS ONLY - NO SPECIAL CHARACTERS

By alphanumeric i mean letters (alpha) and numbers (numerics) only..
no !@#$%^&*(*) <---- not a curse word :) etc... thanks!

On Aug 9, 2:55 pm, KLZA wrote:
Hi. Is there a simple validation formula that would restrict a cell
to alpha-numerics only and exclude all other characters? Thanks in
advance. :)



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default VALIDATION USING ALPHA-NUMERICS ONLY - NO SPECIAL CHARACTERS

What about non Latin and/or accented characters, to clarify do you mean only
[A-Z, a-z, 0-9].

Regards,
Peter T


"KLZA" wrote in message
oups.com...
By alphanumeric i mean letters (alpha) and numbers (numerics) only..
no !@#$%^&*(*) <---- not a curse word :) etc... thanks!

On Aug 9, 2:55 pm, KLZA wrote:
Hi. Is there a simple validation formula that would restrict a cell
to alpha-numerics only and exclude all other characters? Thanks in
advance. :)





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 64
Default VALIDATION USING ALPHA-NUMERICS ONLY - NO SPECIAL CHARACTERS

yes, 0-9 and a-z only...

On Aug 9, 5:06 pm, "Peter T" <peter_t@discussions wrote:
What about non Latin and/or accented characters, to clarify do you mean only
[A-Z, a-z, 0-9].

Regards,
Peter T

"KLZA" wrote in message

oups.com...



By alphanumeric i mean letters (alpha) and numbers (numerics) only..
no !@#$%^&*(*) <---- not a curse word :) etc... thanks!


On Aug 9, 2:55 pm, KLZA wrote:
Hi. Is there a simple validation formula that would restrict a cell
to alpha-numerics only and exclude all other characters? Thanks in
advance. :)- Hide quoted text -


- Show quoted text -





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default VALIDATION USING ALPHA-NUMERICS ONLY - NO SPECIAL CHARACTERS

I don't think you can do that with data validation, would need to process in
a worksheet change event, or flag an adjacent cell with a UDF.

Have a go with this (there are other radically different approaches) -

'' code in the Worksheet module
'' right click sheet tab view code
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long
Dim s As String
Dim rng As Range
Dim cel As Range
Dim byArr() As Byte
Static bRep As Boolean

If bRep Then
bRep = False
Exit Sub
End If

' traps all changing text cells on the sheet
' if necessary adapt if only want to process certain cell(s) or area(s)

If Target.Count = 1 Then
If Not Target.HasFormula And Len(Target) Then
If Not IsNumeric(Target) Then Set rng = Target
End If
Else
On Error Resume Next
Set rng = Target.SpecialCells(xlCellTypeConstants, 2)
End If

On Error GoTo errExit
If Not rng Is Nothing Then

For Each cel In Target.Cells

byArr = cel.Text

For i = 0 To UBound(byArr) Step 2
If byArr(i + 1) Then
'some char's with code 127+ have value in the second byte
'set the 1st byte value to code 35, a "#"
byArr(i) = 35
'clear the 2nd byte
byArr(i + 1) = 0
bRep = True
Else
Select Case byArr(i)
Case 32, 48 To 57, 65 To 90, 97 To 122
'space, 0-9, A-Z, a-z do nothing
Case Else
' set the byte value to code 35, a "#"
byArr(i) = 35
bRep = True
End Select
End If
Next

If bRep Then
s = byArr
cel.Value = Replace(s, "#", "")
bRep = False
End If

Next

End If
errExit:

End Sub

Code assumes you also want to allow spaces, if not remove 32, in the select
case.

'' in a normal module
Sub SampleText()
Dim i&, s$
For i = 33 To 255
s = s & Chr(i)
Next
Selection = s
End Sub


Regards,
Peter T


"KLZA" wrote in message
oups.com...
yes, 0-9 and a-z only...

On Aug 9, 5:06 pm, "Peter T" <peter_t@discussions wrote:
What about non Latin and/or accented characters, to clarify do you mean

only
[A-Z, a-z, 0-9].

Regards,
Peter T

"KLZA" wrote in message

oups.com...



By alphanumeric i mean letters (alpha) and numbers (numerics) only..
no !@#$%^&*(*) <---- not a curse word :) etc... thanks!


On Aug 9, 2:55 pm, KLZA wrote:
Hi. Is there a simple validation formula that would restrict a cell
to alpha-numerics only and exclude all other characters? Thanks in
advance. :)- Hide quoted text -


- Show quoted text -





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default VALIDATION USING ALPHA-NUMERICS ONLY - NO SPECIAL CHARACTERS

Typo in the Worksheet_Change routine

change -
For Each cel In Target.Cells

to -
For Each cel In rng.Cells

Regards,
Peter T

"Peter T" <peter_t@discussions wrote in message
...
I don't think you can do that with data validation, would need to process

in
a worksheet change event, or flag an adjacent cell with a UDF.

Have a go with this (there are other radically different approaches) -

'' code in the Worksheet module
'' right click sheet tab view code
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long
Dim s As String
Dim rng As Range
Dim cel As Range
Dim byArr() As Byte
Static bRep As Boolean

If bRep Then
bRep = False
Exit Sub
End If

' traps all changing text cells on the sheet
' if necessary adapt if only want to process certain cell(s) or area(s)

If Target.Count = 1 Then
If Not Target.HasFormula And Len(Target) Then
If Not IsNumeric(Target) Then Set rng = Target
End If
Else
On Error Resume Next
Set rng = Target.SpecialCells(xlCellTypeConstants, 2)
End If

On Error GoTo errExit
If Not rng Is Nothing Then

For Each cel In Target.Cells

byArr = cel.Text

For i = 0 To UBound(byArr) Step 2
If byArr(i + 1) Then
'some char's with code 127+ have value in the second byte
'set the 1st byte value to code 35, a "#"
byArr(i) = 35
'clear the 2nd byte
byArr(i + 1) = 0
bRep = True
Else
Select Case byArr(i)
Case 32, 48 To 57, 65 To 90, 97 To 122
'space, 0-9, A-Z, a-z do nothing
Case Else
' set the byte value to code 35, a "#"
byArr(i) = 35
bRep = True
End Select
End If
Next

If bRep Then
s = byArr
cel.Value = Replace(s, "#", "")
bRep = False
End If

Next

End If
errExit:

End Sub

Code assumes you also want to allow spaces, if not remove 32, in the

select
case.

'' in a normal module
Sub SampleText()
Dim i&, s$
For i = 33 To 255
s = s & Chr(i)
Next
Selection = s
End Sub


Regards,
Peter T


"KLZA" wrote in message
oups.com...
yes, 0-9 and a-z only...

On Aug 9, 5:06 pm, "Peter T" <peter_t@discussions wrote:
What about non Latin and/or accented characters, to clarify do you

mean
only
[A-Z, a-z, 0-9].

Regards,
Peter T

"KLZA" wrote in message

oups.com...



By alphanumeric i mean letters (alpha) and numbers (numerics) only..
no !@#$%^&*(*) <---- not a curse word :) etc... thanks!

On Aug 9, 2:55 pm, KLZA wrote:
Hi. Is there a simple validation formula that would restrict a

cell
to alpha-numerics only and exclude all other characters? Thanks

in
advance. :)- Hide quoted text -

- Show quoted text -







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
separation alpha numerics Rod Excel Discussion (Misc queries) 5 January 25th 10 04:18 PM
EXCEL: REMOVING A SPECIAL CHARACTER IN A STRING OF ALPHA/NUMERICS RON I Excel Programming 2 July 25th 07 01:38 PM
A validation rule on Alpha and Numeric characters Sar* Excel Worksheet Functions 11 June 11th 07 11:47 PM
code for seperating alpha numerics saziz[_76_] Excel Programming 0 April 26th 06 10:51 PM
Data validation, alpha or numeric characters tsammons Excel Programming 4 January 11th 06 02:03 AM


All times are GMT +1. The time now is 01:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"