Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Setup / February 2007

Tip: Looking for answers? Try searching our database.

Data Validation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kimberly - 07 Feb 2007 18:46 GMT
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)
Mark - 08 Feb 2007 01:39 GMT
On Feb 7, 12:46 pm, Kimberly <Kimbe...@discussions.microsoft.com>
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
Roger Govier - 08 Feb 2007 09:46 GMT
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)

Signature

Regards

Roger Govier

> Can anyone help me validate a column to allow only text and spaces.
> No
[quoted text clipped - 3 lines]
>
> =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)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.