ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   check variable(text) with cell (text), textbox (https://www.excelbanter.com/excel-programming/275416-check-variable-text-cell-text-textbox.html)

Mark[_17_]

check variable(text) with cell (text), textbox
 
I have a problem with compare variable (text-word) with
contents cell (text), textbox , which have many words.
If any cell, textbox contain word like variable (text)
then execute another macro.

Code below don't produce effect:

Sub compare()

Dim word as String
Dim words as String

If word Like words Then
'another macro
End if

End sub

Is there an easy solution of this problem?

Best regards
Mark

kiat

check variable(text) with cell (text), textbox
 
I use Like operator quite a bit and it works quite well. Your code seems OK
so if it doesn't work look into what you have in 'word' and 'words'. You
can also try InStr:

word = "banana"
words = "banana,apple,orange"
if instr(words,word & ",") then call Fruity(word)

if words like "*" & word & "*" then call fruity(word) 'works as well

"Mark" wrote in message
...
I have a problem with compare variable (text-word) with
contents cell (text), textbox , which have many words.
If any cell, textbox contain word like variable (text)
then execute another macro.

Code below don't produce effect:

Sub compare()

Dim word as String
Dim words as String

If word Like words Then
'another macro
End if

End sub

Is there an easy solution of this problem?

Best regards
Mark





All times are GMT +1. The time now is 03:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com