Excel VBA Code for copying data from any updated cell in specific column from one sheet and pasting it, with timestamp, in another sheet

cfrenomaly

New Member
Joined
Apr 19, 2021
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
I have 2 sheets involved:
Sheet2 (Asset List)
Sheet3 (Asset Location History)

This is my current code in Sheet2 (AssetList):
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xLocationColumn As Integer
Dim xUserTimeColumn As Integer
Dim xRow, xCol As Integer
Dim xDPRg, xRg As Range
xLocationColumn = 8
xUserTimeColumn = 10
xRow = Target.Row
xCol = Target.Column
If Target.Text >= "" Then
If xCol = xLocationColumn Then
Cells(xRow, xUserTimeColumn) = Application.UserName & " - " & Format(Now(), "m/d/yyyy, h:mm AM/PM")
Else
On Error Resume Next
Set xDPRg = Target.Dependents
For Each xRg In xDPRg
If xRg.Column = xLocationColumn Then
Cells(xRg.Row, xUserTimeColumn) = Application.UserName & " - " & Format(Now(), "m/d/yyyy, h:mm AM/PM")
End If
Next
End If
End If
End Sub


The above code inputs the logged in UserName and the time in Column 10 ("J"), whenever there is an update in any row in Column 8 ("H"). The input goes into the same respective row as the update. Below is a test sample for what currently happens:

Sheet2 (Asset List).PNG


I need to add to this code so an additional input happens. I need the data from an update in any row in Column 8 ("H") to be copied and input with the time, in Sheet3 (Asset Location History), in Column 3, into the same respective row as the update from Sheet2 (Asset List). The paste needs to be in a new cell, moving old data (data with timestamps) to the right, creating reverse chronology. Below is a test sample of what I am looking to add:

Sheet3 (Asset Location History) 1.PNG


A subsequent update in the same Row 2 Column 8 on Sheet2 (Asset List) would push existing data in Row 2 Column 3 on Sheet3 (Asset Location History) to the right into Column 4. Below is a test sample:

Sheet3 (Asset Location History) 2.PNG


I'm assuming I will need to move new code from Sheet2 to ThisWorkbook, since multiple sheets will be involved with new code?

I appreciate anyone's time and assistance.

Thank you.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,214,926
Messages
6,122,305
Members
449,079
Latest member
juggernaut24

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