如何防止在添加或删除行时运行Worksheet_Change事件?

时间:2015-07-07 14:51:38

标签: excel vba

在编程方面,我完全是新手。我正在处理电子表格以捕获培训信息。下面列出的代码输入用户名(从模块定义用户名作为Window用户名),日期和时间。我的问题是,当添加或删除行时,它会导致子运行。我该怎么做才能防止这种情况发生?在此先感谢您的帮助!

Private Sub Worksheet_Change(ByVal Target As Range)
Set Rng = Range("D11:D88")
If Not Intersect(Target, Rng) Is Nothing Then
  Application.EnableEvents = False
  Target(1).Offset(0, 1).Value = Environ$("username")
  Target(1).Offset(0, 2).Value = Date
  Target(1).Offset(0, 3).Value = Time
  Application.EnableEvents = True
End If
End Sub

1 个答案:

答案 0 :(得分:1)

试试这个:

//INSTANT C# NOTE: C# does not support parameterized properties - the following property has been rewritten as a 'set' method:
//ORIGINAL LINE: Public WriteOnly Property Text(ByVal index As Integer) As String
    public void set_Text(int index, string value)
    {
        lblTemp[index].Text = value;
    }