I am not sure what you are trying to achieve however I am not sure worksheet change event is what you want - it is essentially to detect a change in a worksheet and if condition is met then do something. For example
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1:H1")) Is Nothing Then
Select Case Target.Value
Case Is = "pie"
Call macro1
Case Is = "american"
Call macro2
Case Else
MsgBox "Not found"
End Select
End If
End Sub
Sub macro1()
MsgBox "Macro1"
End Sub
Sub macro2()
MsgBox "Macro2"
End Sub
So if you enter "american" anywhere in range A1 to H1 then macro2 is run and if you enter "pie" anywhere from A1 to H1 in the worksheet then macro1 is called.
What you want to do is check A1 and B1 for the words "american" or "pie" and if so run macro1 if not then check A2 and B2 and so on till you get to the end of the row. That is more suited to a module rather than a worksheet change event. For example
Sub test()
For k = 1 To Cells(Rows.Count, "A").End(xlUp).Row
If Range("A" & k) = "pie" Or Range("B" & k) = "american" Then
Call macro1
Exit For ' will stop execution as have found a value
End If
Next
End Sub
Sub macro1()
MsgBox "Macro1"
End Sub
I would suggest you upload a sample workbook as your question is ambiguous - in your code you are looking for the word "each" however you go on to talk about different strings in the thread. I would suggest you are a little more specific and give a sample workbook showing how your workbook is set up and what you want to happen when certain conditions are met.
Bookmarks