Is there a way to write a VBA that will search a Userform text box for several words, then if a word from the list is in the textbox a message will open up? I have no idea on how to code this. Thank you in advance.
Const WORD_SOUGHT As String = "hello"
Dim Spos As Long
Spos = InStr(1, TextBox1.Text, WORD_SOUGHT, vbTextCompare)
If Spos > 0 Then
With TextBox1
.SetFocus
.SelStart = Spos - 1
.SelLength = Len(WORD_SOUGHT)
End With
MsgBox "the word : '" & WORD_SOUGHT & "' was found."
End If
So I would do this for every word that I want it to look for?
I would like to use VBTextcompare method to search the list of words that will be in column AA, then if the word does not match a word in the column I would like it to copy the textbox1 into the clipboard.
Private Sub CommandButton1_Click()
Dim oTargetRange As Range
Dim oDataObject As Object
On Error Resume Next
Set oTargetRange = Me.Columns("A:A").Find _
(What:=TextBox1.Text, After:=Cells(1))
On Error GoTo 0
If oTargetRange Is Nothing Then
Set oDataObject = _
GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
With oDataObject
.Clear
.SetText TextBox1.Text
.PutInClipboard
End With
End If
End Sub
For whatever reason it does not like Me.Columns("A:A") it gives me an error:
Compile error:
Method or data member not found and the .Columns is highlighted in green.