简体   繁体   English

如何使用vba循环浏览已过滤的表格并检查每一行是否在另一张纸中?

[英]How can I loop through a filtered table and check if each row is in another sheet using vba?

I have 2 worksheets. 我有2个工作表。 Lets call them worksheet A and worksheet B. In worksheet AI automatically pull in a huge amount of data and apply the proper filters to narrow down to the critical data (see image) 让我们将它们称为工作表A和工作表B。在工作表AI中,AI自动提取大量数据并应用适当的过滤器以缩小关键数据的范围(见图)。

this next part is where I need help: 下一部分是我需要帮助的地方:

  1. loop through only the visible rows in sheet A 仅循环通过工作表A中的可见行
  2. check if the first column matches any row in the first column of sheet b 检查第一列是否与工作表b第一列中的任何行匹配
  3. if it does match then I need to check that the second column in that same row in sheet A also matches the second column in the matched row in sheet B. 如果确实匹配,则需要检查工作表A中同一行的第二列是否也匹配工作表B中的匹配行中的第二列。
  4. if it passes both those test then I need to copy the whole row and append it to the end of the data in row B. 如果它通过了这两个测试,那么我需要复制整行并将其附加到B行中数据的末尾。

在此处输入图片说明 so far I have: 到目前为止,我有:

    with ThisWorkbook.Sheets(sheet_name) 
    Dim open_package As Range
    Set open_package = ThisWorkbook.Sheets("Open Packages").Range("A2", Range("A" & Rows.Count).End(xlUp))
    Dim rng3 As Range



    Dim rng_package As Range
    Set rng_package = Range("A1", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeVisible)
    Dim cl_package As Range


    For Each cl_package In rng_package.Rows
        For Each rng3 In open_package
            MsgBox rng3
            Debug.Print (cl_package.Cells(1) & " " & cl_package.Cells(2))
        Next rng3
    Next cl_package
End With

I am trying to troubleshoot the nested loop to see exactly in what way is it looping through everything. 我正在尝试对嵌套循环进行故障排除,以查看它以什么方式循环遍历所有内容。

Ivan! 伊万!

I made a code to loop only visible rows from first table and lookup them in second table, when you find a match between Transaction and Package you append a line to second table 我编写了一个代码以仅循环第一个表中的可见行,并在第二个表中查找它们,当您在Transaction和Package之间找到匹配项时,将一行附加到第二个表中

Sub LoopALL()

  Dim i As Long
  Sheets("A").Select
  Range("A1048576").End(xlUp).Select 'selects the last visible row
  LVR = ActiveCell.Row + 1

  While Cells(LVR, 1).EntireRow.Hidden = True
      LVR = LVR + 1
  Wend

  'End of Table, first row blank
  EoT = LVR

  For i = 2 To EoT
  Sheets("A").Select


      If Cells(i, 1).EntireRow.Hidden = False Then
        TRS = Cells(i, 1)
        PCK = Cells(i, 2)
        STS = Cells(i, 3)
        DES = Cells(i, 4)


        Sheets("B").Select
        Z = Range("A1048576").End(xlUp).Row

        For x = 2 To Z
          If Cells(x, 1).Value = TRS And Cells(x, 2).Value = PCK Then
             Cells(Z + 1, 1).Value = TRS
             Cells(Z + 1, 2).Value = PCK
             Cells(Z + 1, 3).Value = STS
             Cells(Z + 1, 4).Value = DES
          End If
        Next


      End If

  Next


End Sub

暂无
暂无

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

相关问题 使用VBA遍历每个Excel工作表 - Loop through each excel sheet using vba 如何编写一个 VBA 代码,该代码将循环遍历固定范围并在另一张表中将该范围的每一行填充 N 次(带编号)? - How to write a VBA code that will loop through a fixed range and populate each row of that range N times (with numbering) in another sheet? 如何循环遍历表列以过滤另一个表以通过电子邮件发送每个过滤表? - How to Loop Through A Table Column to Filter Another Table to Send Each Filtered Table By Email? 如何在一个表VBA中循环每个表 - How to loop for each table in one sheet VBA 如何删除 Excel 表中的一行,该表位于使用 VBA 的用户窗体搜索字段找到的另一张表上? - How do I delete a row in an Excel Table that is on another Sheet that was found with a Userform search field using VBA? 如何复制过滤范围,然后使用 vba 将该过滤范围粘贴到同一张纸中的另一个过滤范围 - How to copy filtered range and then to paste that filtered range itno another filtered range in the same sheet using vba VBA 如何循环遍历数组中的每个表 - VBA how do I loop through each table in an array 使用 VBA 将过滤后的数据复制到另一个工作表 - Copy filtered data to another sheet using VBA 根据VBA另一个工作表中的筛选表调整表大小 - Resize Table based on Filtered table in another sheet in VBA 过滤数据的 VBA 检查表 - VBA check sheet for filtered data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM