Worksheet_Change函数可在一台计算机上运行,​​但不能在另一台计算机上运行

时间:2020-01-14 21:09:28

标签: excel vba

我正在尝试使用此处编写的VBA代码-https://www.extendoffice.com/documents/excel/3633-auto-populate-date-in-excel-when-cell-is-updated.html#a1

我在下面粘贴的

该代码似乎可以在一台计算机上完美地工作,但是在另一台计算机上,当我在B列中进行任何更改时,似乎什么也没有发生。我首先想到的是可能禁用了某些选项,但是我不确定在哪里查看或如何比较两台计算机之间的设置

感谢您的帮助

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'Updated by Extendoffice 2017/10/12
    Dim xRg As Range, xCell As Range
    On Error Resume Next
    If (Target.Count = 1) Then
        If (Not Application.Intersect(Target, Me.Range("B:B")) Is Nothing) Then _
            Target.Offset(0, -1) = Date
        Application.EnableEvents = False
        Set xRg = Application.Intersect(Target.Dependents, Me.Range("B:B"))
        If (Not xRg Is Nothing) Then
            For Each xCell In xRg
                xCell.Offset(0, -1) = Date
            Next
        End If
        Application.EnableEvents = True
    End If
End Sub

0 个答案:

没有答案