思路:
循环遍历F列的单元格,与字符”a”,”b”,”c”依次比较,如果匹配成功,则继续提取B列的单元格与10和11比较,如果符合,则将单元格区域写入到一个数组中,最后再将数组的值提取到目标区域
细节:
1、 循环遍历,如果有有正确结果,需提前跳出循环;
2、 因为单元格区域写入到数组的方式是一次性写入,则该数组结构将是一个嵌套数组,所以在最后提取数据写入单元格时,需进行循环遍历。
代码:
Sub t() Dim arr, n, brr Dim rng Dim x, temp n = 1 ReDim arr(1 To n) brr = Array("a", "b", "c") For Each rng In Range("f2:f15") With rng For Each x In brr If .Value = x Then Set temp = .Offset(0, -4) If temp.Value = 10 Or temp.Value = 11 Then arr(n) = temp.Resize(, 5) n = n 1 ReDim Preserve arr(1 To n) GoTo 100 End If End If Next x End With 100: Next rng With Sheets("Sheet2") n = 2 For Each x In arr .Cells(n, "b").Resize(, 5) = x n = n 1 Next x End With End Sub