从数组中导入variables

我怎样才能喂养variables“CatchPhrase”来自每个细胞从列S …? 我需要select列S中每个单元格中包含值的所有行。

问题是col S有不同的数字,col A有628790个数字。

Sub SelectManyRows() Dim CatchPhrase As String Dim WholeRange As String Dim AnyCell As Object Dim RowsToSelect As String CatchPhrase = "10044" 'first undo any current highlighting Selection.SpecialCells(xlCellTypeLastCell).Select WholeRange = "A1:" & ActiveCell.Address Range(WholeRange).Select On Error Resume Next ' ignore errors For Each AnyCell In Selection If InStr(UCase$(AnyCell.Text), UCase$(CatchPhrase)) Then If RowsToSelect <> "" Then RowsToSelect = RowsToSelect & "," ' add group separator End If RowsToSelect = RowsToSelect & Trim$(Str$(AnyCell.Row)) & ":" & Trim$(Str$(AnyCell.Row)) End If Next On Error GoTo 0 ' clear error 'trap' Range(RowsToSelect).Select End Sub 

我需要的例子: 在这里输入图像说明

使用相同的方法是否可以填充行号符合一定的标准没有循环的数组?

您可以返回与S1:S9中的列表相匹配的column A数字(本例中使用了A1:A200 ),如下所示

 Sub GetEm() Dim x x = Filter(Application.Transpose(Application.Evaluate("=if(NOT(ISERROR(MATCH(A1:A200,$S$1:S9,0))),a1:a200,""x"")")), "x", False) End Sub 

第二个小组直接select这些单元格

 Sub GetEm2() Dim x1 x1 = Join(Filter(Application.Transpose(Application.Evaluate("=if(NOT(ISERROR(MATCH(A1:A200,$S$1:S9,0))),""a""&row(a1:a200),""x"")")), "x", False), ",") Application.Goto Range(x1) End Sub 

考虑:

 Sub dural() Dim rS As Range, wf As WorksheetFunction Dim N As Long, aryS As Variant, rSelect As Range Dim i As Long, v As Variant ' ' Make an array from column S ' N = Cells(Rows.Count, "S").End(xlUp).Row Set wf = Application.WorksheetFunction Set rS = Range("S1:S" & N) aryS = wf.Transpose(rS) ' ' Loop down column A looking for matches ' Set rSelect = Nothing N = Cells(Rows.Count, "A").End(xlUp).Row For i = 1 To N v = Cells(i, 1).Value If v = Filter(aryS, v)(0) Then If rSelect Is Nothing Then Set rSelect = Cells(i, 1) Else Set rSelect = Union(Cells(i, 1), rSelect) End If End If Next i ' ' Select matching parts of column A ' rSelect.Select End Sub