【问题标题】:Dynamically expand an excel table based on entries in another table根据另一个表中的条目动态扩展一个excel表
【发布时间】:2017-12-12 06:34:45
【问题描述】:

我正在设置一个电子表格,目的是允许用户按员工和日期输入数据。我想创建一个动态表,该表根据条目扩展到另一个表中。例如,我是否可以根据输入到 TABLE2 的新员工自动扩展 TABLE1,使其看起来像 TABLE3,使 TABLE3 准备好供新用户在“值”列中输入?

表 1

表 2

表 3

【问题讨论】:

  • 看起来这是以下帖子的副本,虽然我使用的是 Excel 2016,所以现在可能添加了我不知道的功能:stackoverflow.com/questions/8087736/…
  • 您可以通过使用 VBA 来获得所需的结果,如果这是一个选项?另外,您从哪里获得表 3 的日期值?
  • 是的,VBA 是可以接受的,但最好使用公式,因为我将把这本工作簿交给不熟悉 VBA 的人。我刚刚使用 12 月 12 日至 14 日作为表 1 中日期范围的示例,并为表 3 中的每个员工重复了此范围。

标签: excel dynamic excel-formula excel-2016 excel-tables


【解决方案1】:

这不是最好的做事方式,但这可能会对您有所帮助,或者至少为您指明您正在尝试做的事情的正确方向。

如果表1在Sheet1中,表2在Sheet2中,当向表2添加新行时,以下代码将复制该名称并将其粘贴到Sheet 1的表1中三次,然后从记录中复制日期上面,在这种情况下是比尔的日期。

在 Worksheet Change 事件的 Sheet 2 下放置如下代码,如下图所示:

代码:

Private Sub Worksheet_Change(ByVal Target As Range)
LastRow = Sheet2.Cells(Sheet2.Rows.Count, "A").End(xlUp).Row 'check the last row on Sheet 2 Table 2
LastRow1 = Sheet1.Cells(Sheet1.Rows.Count, "A").End(xlUp).Row + 1 'Check the last row on Sheet1 Table 1

If Target.Row = LastRow Then    'if a new row is added to Table 2
    Sheet1.Cells(LastRow1, Target.Column).Value = Target.Value 'copy their name to table 1 three times
    Sheet1.Cells(LastRow1 + 1, Target.Column).Value = Target.Value
    Sheet1.Cells(LastRow1 + 2, Target.Column).Value = Target.Value

    Sheet1.Cells(LastRow1, 2).Value = Sheet1.Cells(LastRow1, 2).Offset(-3, 0).Value 'copy the Date from the date above on Sheet1
    Sheet1.Cells(LastRow1 + 1, 2).Value = Sheet1.Cells(LastRow1 + 1, 2).Offset(-3, 0).Value
    Sheet1.Cells(LastRow1 + 2, 2).Value = Sheet1.Cells(LastRow1 + 2, 2).Offset(-3, 0).Value
End If
End Sub

【讨论】:

    猜你喜欢
    • 2022-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-17
    • 1970-01-01
    • 1970-01-01
    • 2022-08-17
    • 1970-01-01
    相关资源
    最近更新 更多