【问题标题】:Extract data from one sheet to another based of criteria根据标准将数据从一张纸提取到另一张纸
【发布时间】:2016-06-21 04:32:08
【问题描述】:

如果总取件时间或总交货时间大于 0 到 sheet2,我试图弄清楚如何从 sheet1 中仅提取某些数据。我附上了将包含的工作表和示例数据的图片。我知道如何使用高级过滤器执行宏,但我不确定如何处理这个宏,因为页眉上的表格位于 a 列的一侧,而不是位于顶部。

谢谢

Sheet1

Sheet2

【问题讨论】:

    标签: excel vba macros advanced-filter


    【解决方案1】:
    Dim sh1 as Worksheet
    Dim sh2 as Worksheet
    Dim sh1x, sh2y as Ineteger  'You have to set sh1x to the column you want to check & sh2y to the row you want the data to be transfered to
    
    
    Set sh1 = ActiveWorkbook.Sheets("Audit")
    Set sh2 = ActiveWorkbook.Sheets("Wait Time")
    
    If sh1.Cells(20, sh1x).Value > 1 or sh1.Cells(21, sh1x).Value > 1 then
       sh2.Cells(sh2y, 1) = sh1.Cells(2, sh1x)
       sh2.Cells(sh2y, 2) = sh1.Cells(3, sh1x)
       sh2.Cells(sh2y, 3) = sh1.Cells(4, sh1x)
       sh2.Cells(sh2y, 4) = sh1.Cells(5, sh1x)
       sh2.Cells(sh2y, 5) = sh1.Cells(6, sh1x)
       sh2.Cells(sh2y, 6) = sh1.Cells(7, sh1x)
       sh2.Cells(sh2y, 7) = sh1.Cells(20, sh1x)
       sh2.Cells(sh2y, 8) = sh1.Cells(21, sh1x)
    End If
    

    如果您这样做,则必须将 sh1x 设置为要检查的列,将 sh2y 设置为要粘贴到的行。如果您想自动执行此操作,请将 sh1x 设置为 2 并将 sh2y 设置为 2 并创建一个循环,每次循环时增加 sh1x 和 sh2y 的值(确保在 IF 之前或之后增加它们的值)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-04
      • 2020-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多