VBA code to add date/time and username if any cell in same row is changed for rows 2 down.

MC1903

New Member
Joined
Jun 17, 2006
Messages
6
Hi,

I am looking to do something similar to the solution to this post - Show last date a cell was modified

I am trying to capture the date/time and username details for changes to any cell in that row (from row 2 downwards), but I need to ignore changes in row 1; as it has my headers/sort.

I want the date/time in col A and the username in col B of each row. Any changes from col C to the right (prob to IZ) for that row should update col A & B for that row.

Carbonite PowerShell - Test.xlsm
ABCDE
1Row Last Changed (Date/Time)Row Last Changed By UserData1Data2Data3
220/01/2022 09:59mc190312ALemons
319/01/2022 10:05mc190314BOranges
420/01/2022 10:00mc190318CApples
520/01/2022 09:59mc190315DOranges
619/01/2022 10:05mc190315EApples
719/01/2022 10:05mc190319FLemons
819/01/2022 10:05mc190319GLemons
920/01/2022 09:59mc190321HOranges
1019/01/2022 10:05mc190312IApples
1120/01/2022 09:59mc190322JLemons
1219/01/2022 10:05mc190322KLemons
Sheet1


This is what I have so far, could someone please educate me on what to modify in order to accommodate my needs?

VBA Code:
Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("C2:C" & Range("C" & Rows.Count).End(xlUp).Row)) Is Nothing Then     ' Value in Column C changed
        Range("A" & Target.Row).Value = Format(Now, "dd/mm/yyyy hh:MM")                                 ' Update Column A cell value with date/time
        Range("B" & Target.Row).Value = Application.Username                                            ' Update Column B cell value with username
    End If
End Sub

Any help or pointers will be greatly appreciated.

Cheers
M
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi, try changing

VBA Code:
If Not Intersect(Target, Range("C2:C" & Range("C" & Rows.Count).End(xlUp).Row)) Is Nothing Then

to

VBA Code:
If Not Intersect(Target, Range("C2:IV" & Range("C" & Rows.Count).End(xlUp).Row)) Is Nothing Then
 
Upvote 0
Hi, try changing

VBA Code:
If Not Intersect(Target, Range("C2:C" & Range("C" & Rows.Count).End(xlUp).Row)) Is Nothing Then

to

VBA Code:
If Not Intersect(Target, Range("C2:IV" & Range("C" & Rows.Count).End(xlUp).Row)) Is Nothing Then

Cheers @*JW00.

Nice and simple. Really appreciated; I was testing without formatting my cells as a table and it was updating row 1. ?

M
 
Upvote 0
Thanks, no worries just glad it's working for you.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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