2

The simply command in the Sheet1 module:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
    Range("J5:M5").ClearContents
End Sub

causes Excel to crash.

Community
  • 1
  • 1
Mario Palumbo
  • 693
  • 8
  • 32

1 Answers1

4

You are going into a infinite loop. When you clear your cell, you reactivate the macro, and then when you clear your cell, you reactivate the macro, and then when you clear your cell.....

Disable events before you make your change and the re-enable them with

Application.EnableEvents = False
    Range("J5:M5").ClearContents
Application.EnableEvents = True

You may also want to consider applying this to a specific range. Do you really want any change on this sheet to trigger your macro? Or are you looking for a change in a specific region? If so, specify the region, and run the macro when that region Intersects (overlaps) with the changed cell.

urdearboy
  • 14,439
  • 5
  • 28
  • 58