简体   繁体   English

VBA代码用于在同一Excel工作簿中使用来自两个不同工作表的更新来填充MI电子表格

[英]VBA Code to populate an MI spreadsheet with updates from two different sheets in the same Excel workbook

I have three Excel worksheets: Sheet 1, Sheet 2,Sheet 3 all with the same standard data(Column A to E are standard data in all sheets) Columns F to JF are calendar days/Months. 我有三个Excel工作表:表1,表2,表3都具有相同的标准数据(列A到E是所有表中的标准数据)列F到JF是日历天/月。 The difference being any update to sheet one is a number in a cell in the calendar corresponding to the Names in Column A while update to Sheet 2 is only a highlight for the applicable cell (cells updated are never the same corresponding cell in Sheet 1 or vice versa - which I think makes sense). 不同之处在于对表1的任何更新是日历中与列A中的名称对应的单元格中的数字,而对表单2的更新仅是适用单元格的突出显示(更新的单元格从不是表单1中的相应单元格或反之亦然 - 我认为这是有道理的)。

Sheet 3 needs to update for every update(s) to sheet 1 and 2. 表3需要针对表1和表2的每个更新进行更新。

I am looking to use VBA to do this update to sheet 3. 我期待使用VBA对表3进行此更新。

Add this to the module associated with Sheet 1 . 将其添加到与Sheet 1关联的模块中。 The code will copy the modified range as is to Sheet 3 . 代码将修改范围复制到工作表3

Private Sub Worksheet_Change(ByVal Target As Range)
fr = Target.Row
lr = fr - 1 + Target.Rows.Count
fc = Target.Column
lc = fc - 1 + Target.Columns.Count

For i = fr To lr
    For j = fc To lc
        Sheets("Sheet 3").Cells(i, j).Value2 = Sheets("Sheet 1").Cells(i, j).Value2
    Next
Next

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM