咦。。又是我。。。我又来了。。。不过你的分给的好少呀=。=
先贴代码:
Function AAA()
Dim na As Long
Dim ma As Long
Dim ta As Long
Dim ia As Long
Dim ka As Long
Dim ArrARow(3) As Long
na = Range("A65536").End(xlUp).Row
ArrARow(0) = na
ta = 0
For ia = 1 To na
If ta = 2 Then
ArrARow(ta) = na - ia + 1
Exit For
Else
If Rows(na - ia).EntireRow.Hidden = False Then
ta = ta + 1
If ta = 1 Then
ArrARow(ta) = na - ia
End If
End If
End If
Next ia
ka = 0
For ja = 0 To 2
ka = Application.CountIf(Range(Cells(ArrARow(ja), 1), Cells(ArrARow(ja), 1)), "A") + ka
Next ja
AAA = ka
End Function
Function BBB()
Dim nb As Long
Dim mb As Long
Dim tb As Long
Dim ib As Long
Dim kb As Long
Dim ArrBRow(3) As Long
nb = Range("A65536").End(xlUp).Row
ArrBRow(0) = nb
tb = 0
For ib = 1 To nb
If tb = 2 Then
ArrBRow(tb) = nb - ib + 1
Exit For
Else
If Rows(nb - ib).EntireRow.Hidden = False Then
tb = tb + 1
If tb = 1 Then
ArrBRow(tb) = nb - ib
End If
End If
End If
Next ib
kb = 0
For jb = 0 To 2
kb = Application.CountIf(Range(Cells(ArrBRow(jb), 1), Cells(ArrBRow(jb), 1)), "B") + kb
Next jb
BBB = kb
End Function
两个都是Function,Function AAA是用来计算A的,Function BBB是用来计算B的。
B1输入公式=AAA()+RAND()*0
B2输入公式=BBB()+RAND()*0
就会自动计算了,筛选也没问题。
+RAND()*0 是为了让公式能够自动计算。
你判断一下,最后一行的行号, Range(“A65536”).End(xlUp).Row
设定最后3个单元格。
然后再给这3个单元格设定公式,类似下面的,自己根据需要修改
WorksheetFunction.Countif("A",Range(Cells(j, 6), Cells(j, LC)).SpecialCells(xlCellTypeVisible))