Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 如何从大量零件号列表中隐藏包含一个编号的行_Excel_Excel Formula_Excel 2010_Vba - Fatal编程技术网

Excel 如何从大量零件号列表中隐藏包含一个编号的行

Excel 如何从大量零件号列表中隐藏包含一个编号的行,excel,excel-formula,excel-2010,vba,Excel,Excel Formula,Excel 2010,Vba,我希望能够在一个大型电子表格中隐藏行,其中隐藏的每一行都包含一个大型零件号列表中的零件号。零件号列表将添加到每日列表中,并包含数百个零件号。 现实世界的应用程序是,我有一个构建列表,其中包含需要构建的零件号,但我的商店只需要构建某些零件号,因此我希望删除不需要构建的零件号。尽管我们公司不断推出新的零件号,因此列表不断扩大,我们必须在每个项目上构建的项目也会发生变化。我不确定您是如何获得要检查的零件列表的,但隐藏不在给定零件列表中的任何行的循环可以按如下方式完成: Sub HideRows

我希望能够在一个大型电子表格中隐藏行,其中隐藏的每一行都包含一个大型零件号列表中的零件号。零件号列表将添加到每日列表中,并包含数百个零件号。
现实世界的应用程序是,我有一个构建列表,其中包含需要构建的零件号,但我的商店只需要构建某些零件号,因此我希望删除不需要构建的零件号。尽管我们公司不断推出新的零件号,因此列表不断扩大,我们必须在每个项目上构建的项目也会发生变化。

我不确定您是如何获得要检查的零件列表的,但隐藏不在给定零件列表中的任何行的循环可以按如下方式完成:

    Sub HideRows(ByVal PartNumArray As Variant, ByVal ColumnToSearch As String)

Dim LastRowData As Long
Dim i As Long, j As Long
Dim HideRow As Boolean

LastRowData = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row

Rows(1 & ":" & LastRowData).EntireRow.Hidden = False 'Unhide All the rows (optional)

Application.ScreenUpdating = False 'Use this to speed up the processing
For i = LastRowData To 1 Step -1
    HideRow = True
    For j = LBound(PartNumArray) To UBound(PartNumArray)
        If ActiveSheet.Range(ColumnToSearch & i).Text = PartNumArray(j) Then
        'Alternatives for boolean condition
            'ActiveSheet.Range(ColumnToSearch & i).Text like "*" & PartNumArray(j) & "*" 'For similar matches
            'Instr(1, ActiveSheet.Range(ColumnToSearch & i).value, PartNumArray(j)) > 0 'See if the part number is anywhere in the string
            HideRow = False

        End If
        If HideRow Then
            Rows(i).EntireRow.Hidden = True
        End If
    Next 'Part to look for
Next 'Row
Application.ScreenUpdating = True 'Turn this back on so you can click on the screen again

End Sub
诀窍是使用所需的零件列表初始化PartNumArray。我在这里介绍了两种不同的方法:

'Sample of how to call the hide function
Sub TestSample()
    Dim PartNumArray As Variant

    PartNumArray = Array("42", "45A2", "573A-5")

    Call HideRows(PartNumArray, "A")
End Sub

'Sample of how to fill an array from a worksheet
Sub Fill_Array_With_Part_Numbers()
Dim LastRowData As Long, i As Long
Dim PartNumArray() As String
Dim ColumnToSearch As String
ColumnToSearch = "A"

LastRowData = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row

For i = 1 To LastRowData
    ReDim Preserve PartNumArray(0 To (i - 1))
    PartNumArray(i - 1) = ActiveSheet.Range(ColumnToSearch & i).Value
Next

For i = LBound(PartNumArray) To UBound(PartNumArray)
    Debug.Print "Array Index : " & i & " value is : " & PartNumArray(i)
Next i

End Sub

请看。对不起,请详细说明您需要什么。您是否有两张表,一张是零件列表,另一张是您希望在第一张表中忽略的零件列表?