PDA

View Full Version : Solved: check number of words



av8tordude
01-21-2012, 08:53 AM
How can check if there are at least 2 words in a userform combo box?

Bob Phillips
01-21-2012, 09:02 AM
With Me.Combobox1

If Len(.Value) - Len(Replace(.Value, " ", "")) > 1 Then

MsgBox "2 or more words"
End If
End With

av8tordude
01-21-2012, 09:26 AM
Thank you XLD.

av8tordude
01-21-2012, 10:09 AM
I'm using this code to determine if cboName has more than 1 word, if not it triggers a message. Problem I'm running into is if I type in 1 word and hit the space bar then it doesn't trigger the message.

If Len(cboName) - Len(Replace(cboName, " ", "")) < 1 Then
MsgBox "Please enter your full name.", vbExclamation, "PerDiem Traveler v" & Format(Sheets("Security").Range("J2"), "0.0")
cboName.SetFocus

Bob Phillips
01-21-2012, 05:42 PM
Dude,

Use



If Len(Trim(cboName)) - Len(Replace(cboName, " ", "")) < 1 Then
MsgBox "Please enter your full name.", vbExclamation, "PerDiem Traveler v" '& Format(Sheets("Security").Range("J2"), "0.0")
cboName.SetFocus

av8tordude
01-21-2012, 06:01 PM
Doohh...How could I have not thought about trim...lol. Thanks XLD