我有一本包含多张纸的工作簿。我想计算每个工作表中A列的条目数,并在最终工作表中列出它们。例如,
第1页中有30个条目 图纸2有40个条目 表格3列出了条目数
我正在寻找A1和B1中的输出:
表格1 30 工作表2 40
主要挑战之一是未定义张数。几次也可能达到4到5张纸。我们可以建立用户定义的要考虑的张数,然后运行count命令吗?
预先感谢
答案 0 :(得分:0)
COUNTA函数对一个范围内的所有条目进行计数。范围可以是一列。所以
=CountA(A:A) returns the number of entries in column A
您可以添加工作表名称以引用其他工作表中的范围
=CountA(sheet2!A:A) counts all the entries in column A in sheet2
答案 1 :(得分:0)
尝试:
Option Explicit
Sub test()
Dim ws As Worksheet, LastRowWS As Long, LastRowRS As Long
'Loop all worksheets
For Each ws In ThisWorkbook.Worksheets
'Do not count if sheet name is Results. This sheets has the counts
With ws
If .Name <> "Results" Then
'Find last row of worksheet ws column A
LastRowWS = .Cells(.Rows.Count, "A").End(xlUp).Row
With ThisWorkbook.Worksheets("Results")
'Find last row of worksheet Results column A
LastRowRS = .Cells(.Rows.Count, "A").End(xlUp).Row
'Add the results
.Range("A" & LastRowRS + 1).Value = ws.Name
.Range("B" & LastRowRS + 1).Value = LastRowWS
End With
End If
End With
Next ws
End Sub
注意
每张纸的A列都没有标题。
Sheets列A
结果: