Prev Previous Post   Next Post Next
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

What version of excel are you using?

This relies on split which was added in xl2k.

Option Explicit
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub txtDirector_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim myStr As String
Dim mySplit As Variant
Dim ErrorWasFound As Boolean
Dim myErrMsg As String
Dim iCtr As Long

myStr = Application.Trim(Me.txtDirector.Value)
myErrMsg = ""

mySplit = Split(myStr, " ")

ErrorWasFound = False
If (UBound(mySplit) - LBound(mySplit) + 1) < 2 Then
myErrMsg = "Not 2 Names!"
ErrorWasFound = True
End If

For iCtr = LBound(mySplit) To UBound(mySplit)
If Len(mySplit(iCtr)) < 2 Then
ErrorWasFound = True
myErrMsg = myErrMsg & vbLf & "Names too short"
Exit For
End If
Next iCtr

Me.Label1.Caption = myErrMsg

Cancel = ErrorWasFound


End Sub
Private Sub UserForm_Initialize()
Me.Label1.Caption = ""
End Sub


If you're using xl97, you can include this function that was written by Tom
Ogilvy:

Function Split97(sStr As String, sdelim As String) As Variant
'from Tom Ogilvy
Split97 = Evaluate("{""" & _
Application.Substitute(sStr, sdelim, """,""") & """}")
End Function

Change this line:
mySplit = Split(myStr, " ")
to
mySplit = Split97(myStr, " ")



tkaplan wrote:

i have an excel form that i want that after the user enters data, when
he tries to exit text box it validates the data for him and if it's
valid the background changes to white.
i currently have the colors changing if there is any data in the txtbox
at all. i would like it to be that it needs to have two names in the
field - the director's first and last name. so i want it to check the
the first word is more than one letter, followed by a space, and then
at least two more letters.

i am putting the code in the txtDirector_Exit event.
i know the changing color code, i need to code to check the data in the
box.

thanks in advance
tkaplan

--
tkaplan
------------------------------------------------------------------------
tkaplan's Profile: http://www.excelforum.com/member.php...o&userid=22987
View this thread: http://www.excelforum.com/showthread...hreadid=469858


--

Dave Peterson
 
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
Data validation screen size Brad Excel Discussion (Misc queries) 2 July 13th 05 09:18 PM
data validation lists [email protected] Excel Discussion (Misc queries) 5 June 25th 05 07:44 PM
named range, data validation: list non-selected items, and new added items KR Excel Discussion (Misc queries) 1 June 24th 05 05:21 AM
Pulling data from 1 sheet to another Dave1155 Excel Worksheet Functions 1 January 12th 05 05:55 PM
Using Validation List from Another Workbook with Dependent Data Mike R. Excel Worksheet Functions 5 January 8th 05 07:06 PM


All times are GMT +1. The time now is 11:39 PM.

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"