msgbox 在 excel 表中进入无限循环

msgbox goes in Infinite loop in excelsheet

此代码在 worksheet_change 事件上执行。它检查重复的手机号码,如果找到则显示弹出窗口并清除特定的单元格值。

 If Target.Column = 1 Then
  r = Target.Value
  adr = Target.Address(False, False)
  LastRow = ActiveSheet.Cells.SpecialCells(xlLastCell).Row
      For c = 2 To LastRow
          s = Sheets("Create Users").Range("A" & c).Value
          If r = s And adr <> "A" & c Then
              MsgBox ("Dupliacte phone numbers are not allowed.")
             Target.Value = ""
          End If
       Next c
  End If

试试这个

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