|
- Sub 宏1()
- Dim filterRange As Range
- Dim brr() As String, a As Integer, i%, m%
- Dim filterdata() As Variant
- a = ThisWorkbook.Worksheets("sheet5").Range("A1").CurrentRegion.Rows.Count
- ReDim brr(1 To a)
- For i = 1 To a
- brr(i) = Worksheets("sheet5").Range("A" & i).Value
- Dim wa As Worksheet
- Set wa = ThisWorkbook.Worksheets("sheet1")
- Dim arr, rng As Range, RngUnion As Range
- wa.UsedRange.AutoFilter field:=1, Criteria1:=brr(i)
- On Error Resume Next '如果存在文本,会有类型匹配出错提示,忽略提示继续执行
- Set rng = wa.AutoFilter.Range.SpecialCells(xlCellTypeVisible)
- filterdata = rng
- On Error GoTo 0 '恢复
-
- If wa.AutoFilterMode Then
- wa.AutoFilterMode = False '清除筛选
- End If
- Next i
- Set rng = Worksheets("sheet4").Range("A1").CurrentRegion
- arr = rng
- End Sub
复制代码 第一次循环后,数组filterdata内容正确,第二次循环后数组只显示一行。想要实现按学校名称筛选,每次筛选的结果要追加到上一次筛选的结果后面。
|
|