[英]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: 下一部分是我需要帮助的地方:
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.