0
votes

I would like create a macro (VBA) that find a word and in another cell give a word. Example:

|A | B| macro result|
|- |- | -|
|1 |my cat is on the table | ok|
|2 | Hi|                |
|3| this is my house| ok|

I have try this but it doesn't work. Can you help me?

  Sub Macro1()
    riga = 1
    
    While (Sheets("Foglio2").Cells(riga, 1) <> "")
      If (Sheets("Foglio2").Cells(riga, 2) Like "my") Then
         Sheets("Foglio2").Cells(riga, 3) = "ok"
      End If
      riga = riga + 1
    Wend
    
  End Sub
Not sure I correctly understand what you try accomplishing... Do you search in column B:B strings containing "my" and if they exists to write "ok" in C:C? If so, replace If (Sheets("Foglio2").Cells(riga, 2) Like "my") Then with If Instr(Sheets("Foglio2").Cells(riga, 2), "my") > 0 Then - FaneDuru
Why not use a formula like `=IF(COUNTIF( A2:B2; "my")>0;"ok";"-") - FunThomas
@FaneDuru very well, it is work! - Inuraghe