我有一个数据表,标题跨越顶部和左侧。我正在过滤每一列,一次一个(从第2列开始)。我想为过滤后仍然存在的每个行分配一个特定值(左边的标题)到一个数组。但是,我的代码不会从过滤范围中提取,而是从未过滤的范围中提取。例如:我的过滤范围是1,4,8,9行,excel是1,2,3,4。我有什么想法可以修改我的代码吗?
constant = 0: i = 1: o = 1
Application.Visible = True
Set WS_Prods_With = Sheets.Add
For z = 3 To LstCol1
RA_counter = 0: CP_counter = 0: counter = 0
ReDim ProdWith(1 To 1)
ProdWith(1) = "" 'Clearing out array
With WS_Sel
If (.AutoFilterMode And .FilterMode) Or .FilterMode Then
.ShowAllData 'Turning off previous filter
End If
On Error Resume Next
.Range(.Cells(1, 1), .Cells(counter, LstCol1)).AutoFilter Field:=z, Criteria1:="Yes"
Set rngFilter_Yes = Intersect(.UsedRange, .UsedRange.Offset(1), _
.Columns(2)).SpecialCells(xlCellTypeVisible)
LstRow_Yes = .Cells(.Rows.Count, "A").End(xlUp).Row - 1 'last row in filtered column
If LstRow_Yes > 0 Then
Set rngFilter_Yes2 = rngFilter_Yes
ElseIf LstRow_Yes = 0 Then 'No yes's in the column
ReDim Preserve ProdWith(1 To 2)
ProdWith(1) = WS_Sel.Cells(v + 1, 1).Value
ProdWith(2) = "No products"
With WS_Prods_With
.Range(.Cells(z - 2, 1), .Cells(z - 2, 2)) = ProdWith
End With
GoTo NoCells 'skip the rest of the code
End If
End With
For Each cel In rngFilter_Yes2 'check filtered column for yes's! Add to appropriate counter
Select Case cel
Case Is = "~"
Case Is = "RA": RA_counter = RA_counter + 1
Case Is = "Comp": CP_counter = CP_counter + 1
End Select
Next cel
Total = CP_counter + RA_counter
For v = 1 To Total
counter = counter + 1
ReDim Preserve ProdWith(1 To counter)
ProdWith(v) = WS_Sel.Cells(v + 1, 1).Value
Next v