简体   繁体   English

具有多个可变条件的自动过滤器

[英]Autofilter with multiple variable criterias

I have a sheet which contains a column full of Item IDs called "Werkzeugtabelle Vormontage" and another sheet which contains part of the item IDs listed in sheet 1.我有一个工作表,其中包含一列名为“Werkzeugtabelle Vormontage”的项目 ID,另一个工作表包含工作表 1 中列出的部分项目 ID。

I want to filter Sheet 1 by the Item IDs that are similar to the ones in sheet 2. So basically have the sheet with more IDs chopped to the size of the sheet with less IDs.我想通过与工作表 2 中的项目 ID 相似的项目 ID 来过滤工作表 1。因此,基本上将具有更多 ID 的工作表切成具有较少 ID 的工作表的大小。 (Deleting the not similar ones would also be an option but no clue how that might work.) (删除不相似的也是一种选择,但不知道它是如何工作的。)

If CheckSheet("BMV Vormontage") Then
    Sheets("Werkzeugtabelle").Select
    Sheets("Werkzeugtabelle").Copy After:=Sheets("BMV Vormontage")
    ActiveSheet.Name = "Werkzeugtabelle Vormontage"
    lRow = Cells(Rows.Count, 1).End(xlUp).Row
    Sheets("Restanschluss Vormontage").Select
    xRow = Cells(Rows.Count, 11).End(xlUp).Row
    'CountUnique ("K3:K100")
    'critCount = CountUnique.Count
    For i = 3 To lRow
        For a = 10 To xRow
            Sheets("Werkzeugtabelle Vormontage").Cells(i, 1).AutoFilter Field:=1, Criteria1:=Sheets("Restanschluss Vormontage").Cells(a, 11).Value
        Next a
    Next i
End If

The CheckSheet is looking for that sheet to get a starting point in the workbook. CheckSheet 正在寻找该工作表以获取工作簿中的起点。 "Werkzeugtabelle" is the non filtered vanilla sheet. “Werkzeugtabelle”是未经过滤的香草片。

Whenever I have more than one similar Item ID between the two sheets, it won't show, because I am only looking for one criteria it seems.每当我在两张纸之间有多个相似的项目 ID 时,它就不会显示,因为我似乎只是在寻找一个标准。

I tried to do a loop.我试着做一个循环。

Alright I guess I have found the solution.好吧,我想我已经找到了解决方案。 At least it does everything it does and doesn't spam me with error.至少它完成了它所做的一切,并且不会向我发送错误信息。 Could you guys double check if this is a good code?你们能仔细检查一下这是否是一个好的代码吗?

Sub Werkzeugtabelle_splitten()

Dim ws As Worksheet
Dim rng As Variant


Set ws = Sheets("Werkzeugtabelle")

' Splitten Vormontage
If CheckSheet("BMV Vormontage") Then
rng = Sheets("Restanschluss Vormontage").Range("K10:K100").Value

ws.Range("A3").AutoFilter _
Field:=1, _
Criteria1:=Application.Transpose(rng), _
Operator:=xlFilterValues
ws.Copy After:=Sheets("BMV Vormontage")
ActiveSheet.Name = "Werkzeugtabelle Vormontage"
ws.ShowAllData
End If

End Sub

So I have made that the orginial "Werkzeugtabelle" sheet will still exist and it only filters it > copies it to the right spot in the workbook and afterwards resets the filter on the original.所以我已经让原来的“Werkzeugtabelle”表仍然存在,它只过滤它>将它复制到工作簿中的正确位置,然后在原始文件上重置过滤器。

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

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