Option Explicit
Dim Flag As Boolean, NoSelect As Boolean
Private Sub TextBox1_Change()
If TextBox1.Text = vbNullString Then
Flag = False
End If
If Not Flag Then
Call TextboxFill
End If
End Sub
Private Sub CommandButton1_Click()
Sheets("Sheet1").Range("B" & 1).Value = TextBox1.Text
TextBox1.Text = vbNullString
End Sub
Function Checkit(Inputstr As String) As Boolean
Checkit = False
If UCase(Left(Inputstr, 1)) = Left(TextBox1.Text, 1) Or _
LCase(Left(Inputstr, 1)) = Left(TextBox1.Text, 1) Then
If MsgBox(prompt:="Search word: " & Inputstr, Buttons:=vbYesNo, _
Title:="IS THIS YOUR WORD?") = vbYes Then
Checkit = True
Else
NoSelect = True
End If
End If
End Function
Sub TextboxFill()
Dim Lastrow As Long, Cnt As Long, I As Integer, Tstr As String
'words/sentences in sheet1 "A"
'outputs individual words of each cell
'fills textbox with whole cell contents
If TextBox1.Text <> vbNullString Then
Lastrow = Sheets("sheet1").Cells(Rows.Count, "A").End(xlUp).Row
'loop "A"
For Cnt = 1 To Lastrow
NoSelect = False
Tstr = vbNullString
'loop through each cell. Seperate word(s) with " " ie. Asc 32
For I = 1 To Len(Sheets("Sheet1").Range("A" & Cnt).Value)
If Asc(Mid(Sheets("Sheet1").Range("A" & Cnt).Value, I, 1)) <> 32 Then
Tstr = Tstr & Mid(Sheets("Sheet1").Range("A" & Cnt).Value, I, 1) 'make word
Else
If Checkit(Tstr) Then
'If MsgBox(prompt:="Replace textbox contents with: " & Sheets("Sheet1").Range("A" & Cnt).Value, _
Buttons:=vbYesNo, Title:="REPLACE TEXTBOX CONTENTS?") = vbYes Then
Flag = True
TextBox1.Text = Tstr 'Sheets("Sheet1").Range("A" & Cnt).Value
Exit Sub
'End If
End If
Tstr = vbNullString
End If
Next I
'multiword: last word
If Checkit(Tstr) Then
'If MsgBox(prompt:="Replace textbox contents with: " & Sheets("Sheet1").Range("A" & Cnt).Value, _
Buttons:=vbYesNo, Title:="REPLACE TEXTBOX CONTENTS?") = vbYes Then
Flag = True
TextBox1.Text = Tstr 'Sheets("Sheet1").Range("A" & Cnt).Value
Exit Sub
'End If
End If
'offer whole sentence option
If NoSelect = True Then
If MsgBox(prompt:="Replace textbox contents with: " & Sheets("Sheet1").Range("A" & Cnt).Value, _
Buttons:=vbYesNo, Title:="REPLACE TEXTBOX CONTENTS?") = vbYes Then
Flag = True
TextBox1.Text = Sheets("Sheet1").Range("A" & Cnt).Value
Exit Sub
End If
End If
Next Cnt
End If
Flag = False
End Sub