Recording user when changing Active Row

Foynxter1

New Member
Joined
Sep 29, 2016
Messages
40
Help please.
I found this code and have adjusted slightly to fit my needs.
My spreadsheet is called "Additional Charges" and I want to record any user that makes a change anywhere on the active row.

Code is :
'Set the user who modified the record
Dim ThisRow As Long ' make sure to declare all the variables and appropiate types
ThisRow = Target.Row
'protect Header row from any changes
If (ThisRow = 1) Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
MsgBox "Header Row is Protected."
Exit Sub
End If
If Target.Column >= 1 And Target.Column <= 30 Then
MsgBox Target.Column
Dim sOld As String, sNew As String
sNew = Target.Value 'capture new value
With Application
.EnableEvents = False
.Undo
End With
sOld = Target.Value 'capture old value
MsgBox sOld & "Old"
Target.Value = sNew 'reset new value
MsgBox sNew & "New"
If sOld <> sNew Then
Range("E" & ThisRow).Value = Environ("username")
End If
Application.EnableEvents = True
End If

For some reason the code is only recognising column 1 (and recording if column 1 changes) but does not seem to recognise any other column.
I am probably missing something obvious but Any help much appreciated. Thanks
 
Hi - you really are going above & beyond.
The full script for the worksheet is :
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim name As String
    Dim named As String
    If Target.Column <> 1 Or Target.Cells.Count > 1 Then Exit Sub
    If Target.Offset(0, 1).Value = "" Then
        Target.Offset(0, 1) = Format(Now(), "dd/MM/yy")
        'Set the user who created the record
        Cells(Target.Row, 4).Value = UserName()
        named = UserName()
        MsgBox named & " Created"
    End If
    'Set the user who modified the record
    Dim ThisRow As Long    ' make sure to declare all the variables and appropiate types
    ThisRow = Target.Row
    'protect Header row from any changes
    If (ThisRow = 1) Then
        Application.EnableEvents = False
        Application.Undo
        Application.EnableEvents = True
        MsgBox "Header Row is Protected."
        Exit Sub
    End If
    ThisColumn = Target.Column
    If Target.Column >= 1 And Target.Column <= 15 Then
        MsgBox Target.Column
        Dim sOld As String, sNew As String
        sNew = Target.Value    'capture new value
        With Application
            .EnableEvents = False
            .Undo
        End With
        sOld = Target.Value    'capture old value
        MsgBox sOld & "Old"
        Target.Value = sNew    'reset new value
        MsgBox sNew & "New"
        If sOld <> sNew Then
            Range("E" & ThisRow).Value = Environ("username")
        End If
        Application.EnableEvents = True
    End If
End Sub

I am not sure but I think that the conflict might be on the top line as below
" If Target.Column <> 1 Or Target.Cells.Count > 1 Then Exit Sub "

This line was put in to prevent receiving a "1004" error when trying to delete a record but I suspect is upsetting other areas (I need to find time at the weekend to really try and "analyse" in my own amateur way :)). I'm really grateful for any help as there is not really any support in this area within the workplace.
 
Last edited by a moderator:
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,223,277
Messages
6,171,156
Members
452,385
Latest member
Dottj

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top