How can check if there are at least 2 words in a userform combo box?
How can check if there are at least 2 words in a userform combo box?
[vba]
With Me.Combobox1
If Len(.Value) - Len(Replace(.Value, " ", "")) > 1 Then
MsgBox "2 or more words"
End If
End With[/vba]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
Thank you XLD.
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.
[vba]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[/vba]
Dude,
Use
[vba]
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
[/vba]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
Doohh...How could I have not thought about trim...lol. Thanks XLD