A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Setting up and Configuration
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Data Validation



 
 
Thread Tools Display Modes
  #1  
Old February 7th, 2007, 06:46 PM posted to microsoft.public.excel.setup
kimberly
external usenet poster
 
Posts: 107
Default Data Validation

Can anyone help me validate a column to allow only text and spaces. No
punctuation. I used this below and was able to get only text but it also
prevents spaces.

=SUMPRODUCT(--(ISNUMBER(MATCH(CODE(MID(A1,ROW(INDIRECT("1:"&LEN( A1))),1)),ROW(INDIRECT("97:122")),0))))+SUMPRODUCT (--(ISNUMBER(MATCH(CODE(MID(A1,ROW(INDIRECT("1:"&LEN( A1))),1)),ROW(INDIRECT("65:90")),0))))=LEN(A1)



  #2  
Old February 8th, 2007, 01:39 AM posted to microsoft.public.excel.setup
Mark
external usenet poster
 
Posts: 48
Default Data Validation

On Feb 7, 12:46 pm, Kimberly
wrote:
Can anyone help me validate a column to allow only text and spaces. No
punctuation.


Here is a macro that will do the job. Just copy and paste the
following into the worksheet code module that you are working with.
Hope that does it for ya....

Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyString As String
Dim ChrCnt As Integer
Dim MyColumn As Integer
'Set your column number in the next line by changing the
'number 2 after the = sign to the column you want...
MyColumn = 2
'Check to see if this is even the cell we want
If Target.Column = MyColumn Then
'If the cell is blank then allow it and skip the rest
If Target = "" Then
Exit Sub
End If

ChrCnt = Len(Target)
Do Until ChrCnt = 0
MyString = Mid(Target, ChrCnt, 1)
If Asc(MyString) = 65 And Asc(MyString) = 90 Or _
Asc(MyString) = 97 And Asc(MyString) = 122 Or _
MyString = " " Then
Else
'You may change the message displayed by editing the _
'text found in quotes on the next line of code.
MsgBox "Illegal entry Attempted", vbExclamation, _
"Text Only Allowed"
Target = ""
Exit Sub
End If
ChrCnt = ChrCnt - 1
Loop
End If
End Sub


  #3  
Old February 8th, 2007, 09:46 AM posted to microsoft.public.excel.setup
Roger Govier
external usenet poster
 
Posts: 2,602
Default Data Validation

Hi

If you just add the extra case for Space - Code(32) - then this seems to
work

=SUMPRODUCT(--(ISNUMBER(MATCH(CODE(MID(A1,ROW(INDIRECT("1:"&LEN( A1))),1)),ROW(INDIRECT("97:122")),0))))+SUMPRODUCT (--(ISNUMBER(MATCH(CODE(MID(A1,ROW(INDIRECT("1:"&LEN( A1))),1)),ROW(INDIRECT("65:90")),0))))+SUMPRODUCT(--(ISNUMBER(MATCH(CODE(MID(A1,ROW(INDIRECT("1:"&LEN( A1))),1)),ROW(INDIRECT("32:32")),0))))=LEN(A1)

--
Regards

Roger Govier


"Kimberly" wrote in message
...
Can anyone help me validate a column to allow only text and spaces.
No
punctuation. I used this below and was able to get only text but it
also
prevents spaces.

=SUMPRODUCT(--(ISNUMBER(MATCH(CODE(MID(A1,ROW(INDIRECT("1:"&LEN( A1))),1)),ROW(INDIRECT("97:122")),0))))+SUMPRODUCT (--(ISNUMBER(MATCH(CODE(MID(A1,ROW(INDIRECT("1:"&LEN( A1))),1)),ROW(INDIRECT("65:90")),0))))=LEN(A1)





 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:04 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.