Consulting

Results 1 to 6 of 6

Thread: Solved: check number of words

  1. #1

    Solved: check number of words

    How can check if there are at least 2 words in a userform combo box?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [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

  3. #3
    Thank you XLD.

  4. #4
    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]

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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

  6. #6
    Doohh...How could I have not thought about trim...lol. Thanks XLD

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •