我有下面显示的代码。我第一次过滤,效果很好。然而第二次,它没有。过滤的列包含年份。
For i = 1 To LastRow
If wSheet.Range("A1").Offset(i, 0) <> wSheet.Range("A1").Offset(i + 1, 0) Then
WellName = wSheet.Range("A1").Offset(i, 0)
Set rng = wSheet.Range("A1", Cells(LastRow, LastColumn))
rng.AutoFilter Field:=1, Criteria1:=Name
L_top = wSheet.Range("A2:A" & LastRow).SpecialCells(xlCellTypeVisible).Row
L_bot = wSheet.Range("A2:A" & LastRow).SpecialCells(xlCellTypeVisible).Count
LastRowFilter = wSheet.Range("A1").End(xlDown).Row
LastColumnFilter = wSheet.UsedRange.Columns.Count
For j = 1 To LastRowFilter
If Year(wSheet.Range("B1").Offset(j, 0)) <> Year(wSheet.Range("B1").Offset(j + 1, 0)) Then
ReportYear = Year(wSheet.Range("B1").Offset(j, 0))
Set rng2 = wSheet.Range("B1", Cells(LastRowFilter, LastColumnFilter))
rng2.AutoFilter Field:=2, Criteria2:=ReportYear
L_top = wSheet.Range("B2:B" & LastRowFilter).SpecialCells(xlCellTypeVisible).Row
L_bot = wSheet.Range("B2:B" & LastRowFilter).SpecialCells(xlCellTypeVisible).Count
End If
Next
End If
Next