在范围列中记录编辑的用户

时间:2019-03-10 20:27:07

标签: excel vba

此VBA脚本在A列中记录了修改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) = Application.UserName
        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) = Application.UserName
            Next
        End If
        Application.EnableEvents = True
    End If
End Sub

我需要一个脚本来:在A列中输入在B:S列中编辑过的pc用户的名字

1 个答案:

答案 0 :(得分:2)

因此,您希望将用户名写在A列中,在该行上,B列中对S所做的任何更改都是正确的吗? 像这样:

Private Sub Worksheet_Change(ByVal Target As Range)
    If (Target.Count = 1) And Not Application.Intersect(Target, Range("B:S")) Is Nothing Then
        Cells(Target.Row, 1) = Application.UserName
    End If
End Sub