我正在努力找到可以使用VBA返回excel列中多个匹配的行号的公式。我想存储列中找到匹配“267874”的所有行的值。数组应存储行号(7:9)
我正在使用的当前公式是 “countif”查找匹配数量 “loop”countif值并在f(i)中存储匹配
tbb::make_atomic
答案 0 :(得分:0)
试试这个:
Option Explicit
Sub test()
Dim lRow As Long, iCell As Range, arrRow(), i As Long
Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets("YourSheetNameHere")
If ws.FilterMode Then ws.ShowAllData
lRow = ws.Range("A" & ws.Rows.Count).End(xlUp).Row
ReDim arrRow(lRow)
ws.Range("A5", "E" & lRow).AutoFilter Field:=2, Criteria1:="*Invalid*"
i = 0
For Each iCell In ws.Range("A6", "A" & lRow).SpecialCells(xlCellTypeVisible)
arrRow(i) = iCell.Row
i = i + 1
Next
ReDim Preserve arrRow(i - 1)
End Sub