The code as provided does work as expected. Which maybe implies you didn't just copy and paste it.
JosephP has explained the Intersect function. But there are different ways of testing if the cell that has been changed is the (or a) cell that you are interested in.
I prefer:
If Intersect (Target, Range("B4")) Is Nothing Then Exit Sub
... because that says if the Target cell isn't B4, exit the Change event code. Then you don't have all the rest of your event code nested in an IF ... End IF (and maybe forget to put the last End If in). It's perhaps more use for a longer range or a whole column but I always use this method
So, the alternative is:
If Not Intersect (Target, Range("B4")) Is Nothing Then
If Me.Range("B4").Value = "(All)" Then Exit Sub
Sheets("Sheet2").Range("X6").Value = Me.Range("B4").Value
End IF
If you just want to check one cell, you can say, for example:
If Target.Address <> Range("B4").Address Then Exit Sub
If Me.Range("B4").Value = "(All)" Then Exit Sub
Sheets("Sheet2").Range("X6").Value = Me.Range("B4").Value
That said, I think you end up typing more to get less.
Anyway, that's your choice. Incidentally, although I put it in here, you don't actually need the ".Me"
Note that I have qualified the output address with Sheets("Sheet2"). If you don't do that, you will be making a change to another cell on the same sheet. Which might explain the looping.
If you are making changes on the same sheet, you need:
If Not Intersect (Target, Range("B4")) Is Nothing Then
Application.EnableEvents=False
If Range("B4").Value = "(All)" Then Exit Sub
Range("X6").Value = Range("B4").Value
Application.EnableEvents=True
End IF
Regards, TMS
Bookmarks