How to change a cell value in worksheet change event in vba

71 Views Asked by At

Actually using the following code is impossible, because we are doing a change in Worksheet_Change

Private Sub Worksheet_Change(ByVal Target As Range) Target.Value = "test" End Sub

It will make an unlimited loop in the event

I must change the target only in this event

Do you have a solution to resolve this problem?

1

There are 1 best solutions below

0
kevin On

Use Application.EnableEvents = False to prevent Excel from recognizing the change event.

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False
Target.Value = "test"
Application.EnableEvents = True

End Sub