我在excel中有一个类似的表:
A B C A A
m n k m l
n m r s t
u i v z
我想要计算标题行X的多少个coloumns(例如," A"),字符串" m"出现。
我尝试使用某些数组函数但没有成功,我似乎无法根据第一行过滤值。
提前致谢!
答案 0 :(得分:0)
选择表格,包括标题行并运行此小宏:
Sub MCounter()
Dim TopRow As Range, r As Range
Dim SomeCol As Range, K As Long
Dim wf As WorksheetFunction
Set wf = Application.WorksheetFunction
Set TopRow = Intersect(Selection(1).EntireRow, Selection)
K = 0
For Each r In TopRow
If r.Value = "A" Then
Set SomeCol = Intersect(r(1).EntireColumn, Selection)
If wf.CountIf(SomeCol, "m") > 0 Then
K = K + 1
End If
End If
Next r
MsgBox K
End Sub
答案 1 :(得分:0)
可能是这样的:
=IFERROR(IF(A1="A",MATCH("m",A2:A4,0),),"")
每列然后对结果求和。
答案 2 :(得分:0)
执行数组函数:
=SUM((A1="A")*(A2:A1000="m"))
然后对该行求和