i think to count space cause every word will separated with space.

Private Sub Command1_Click()
Dim Counts As Integer
If Text1.Text = "" Then
    Counts = 0
Else
    Counts = 1
    For i = 1 To Len(Text1.Text)
        If Then 'this part i don't know how to search the space
            Counts = Counts + 1
        End If
    Next
End If
MsgBox Counts
End Sub

Use Mid function to search space in text box:

Private Sub Command1_Click()
Dim Counts As Integer
If Text1.Text = "" Then
    Counts = 0
Else
    Counts = 1
    For i = 1 To Len(Text1.Text)
        If Mid(Text1.Text, i, 1) = " " Then ' use Mid to search space
            Counts = Counts + 1
        End If
    Next
End If
MsgBox Counts
End Sub

Edited 5 Years Ago by Jx_Man: n/a

Comments
Usefull
Thanks for Mid function
Why do you insist on doing their homework?

What if there are 2 or more spaces between some words?
Did you count the first word? It has no space in front of it.
Did you consider the way many people now incorrectly write? They never add a space after a sentence -- just run the 2 sentences together.

Things to think about.

By this below codes you can check how many words are there on single line or multi line text box even if user enter space in between and before or after words.

Private Sub Command1_Click()
Dim Counts As Integer
Dim dupText As String

dupText = Replace(Trim(Text1.Text), vbNewLine, " ")

If dupText = "" Then
    Counts = 0
Else
    Counts = 1
    For i = 1 To Len(dupText)
        If Mid(dupText, i, 1) = " " Then ' use Mid to search space
            If Mid(dupText, i - 1, 1) <> " " Then
                Counts = Counts + 1
            End If
        End If
    Next
End If
MsgBox Counts
End Sub
Comments
and thanks for doing his homework for him. Now he doesn't have to think.
Thanks for duplicate checking :)
agree
This question has already been answered. Start a new discussion instead.