[英]Timestamp on one sheet from updated cell on another VBA excel
I have a workbook with upto 31 sheets,(named (01),(02) etc, Each with the same format as per the screenshot below 我有一本多达31张的工作簿,名为(01),(02)等,每张的格式与下面的屏幕截图相同
I wish to use the following code which I have found(with help from this forum :) ) to place a timestamp in a mirror file (WorkBook2) that will work out the difference from when column B and Column C in workbook 1 is changed. 我希望使用下面找到的代码(在此论坛的帮助下):)将时间戳记放置在镜像文件(WorkBook2)中,该文件将计算出与更改工作簿1中的B列和C列的区别。
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range("B:B, C:C"), Target) Is Nothing Then 'add Columns that will be changed to BA:BA and BB:BB
'add error control
On Error GoTo safe_exit
'don't do anything until you know something has to be done
Dim r As Range
Application.EnableEvents = False
For Each r In Intersect(Range("B:B, C:C"), Target) 'i know this would only work on the same sheet
r.Offset(0, 1).Value = Now() 'Need to get this section to populate workbook2
Next r
End If
safe_exit:
Application.EnableEvents = True
End Sub
I know people have asked similar questions and im sorry if this is a duplicate but I really am lost on trying to get this to work. 我知道人们也曾问过类似的问题,如果这是重复的,我很抱歉,但是我真的迷失了如何使它起作用。
Edit - Workbook two sheets are named in the same way with just a "t" after ie (01t), (02t) etc 编辑-工作簿的两张工作表以相同的方式命名,即(01t),(02t)等
Try this. 尝试这个。 The code needs to go in the ThisWorkbook module of workbook 1 and you need to add the name of workbook 2. 该代码需要进入工作簿1的ThisWorkbook模块中,并且需要添加工作簿2的名称。
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim r As Range
On Error GoTo safe_exit
Application.EnableEvents = False
For Each r In Target
Select Case r.Column
Case 2, 3, 5, 6, 8, 9, 11, 12 'b c e f h i k l
Workbooks("name of workbook2").Sheets(Sh.Name & "t").Range(r.Address).Value = Now()
End Select
Next r
safe_exit:
Application.EnableEvents = True
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.