简体   繁体   English

一张纸上的时间戳来自另一个VBA Excel上更新的单元格

[英]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)等,每张的格式与下面的屏幕截图相同 工作簿1

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

工作簿2

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.

相关问题 Excel 使用 VBA 将单元格数据从一张纸复制到另一张纸 - Excel Copy Cell Data from one sheet to another using VBA Excel VBA - 将单元格内容从一张纸复制到另一张纸 - Excel VBA - copying cell contents from one sheet to another 从一个单元格中获取价值并将其集中在另一张表上 Vba Excel - Get Value from one cell and focus it on another sheet Vba Excel Excel VBA 从一个工作表中复制范围并将其一次一个单元格地粘贴到另一张工作表中 - Excel VBA copy range from one sheet and paste it one cell at a time in another sheet 基于另一张工作表中的单元格隐藏一张工作表中的列 - Excel VBA - Hide columns in one sheet based on a cell from another sheet - Excel VBA VBA从一个Excel工作表复制到另一个Excel工作表? - VBA copying from one excel sheet to another excel sheet? Excel VBA 根据第二列单元格值将列从一张表复制到另一张表 - Excel VBA to Copy Column from one sheet to another based on a second columns cell value 来自另一张纸的单元格焦点 DoubleClick Vba Excel - Cell Focus from another sheet DoubleClick Vba Excel 如何从Module-Excel VBA中的另一个工作表引用单元格? - How to reference cell from another sheet in Module - Excel VBA? 在一个工作表中查找单元格文本,在另一工作表中查找,然后用vba偏移 - Find cell text from one worksheet, in another sheet, then offset with vba
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM