This Works。您可能需要更新範圍參考。它在單獨的工作表上輸出摘要。
Sub UserNameCount()
Dim headers As Range, header As Range, countRng As Range, col As Long
Set dict = CreateObject("Scripting.Dictionary")
Set headers = Range("A1:G1")
col = 1
For Each header In headers
Set countRng = Range(header.Offset(1, 0), header.Offset(5, 0)) //update the '5' depending on the number of rows you have
If Not dict.Exists(header.Value) Then
dict.Add header.Value, WorksheetFunction.CountA(countRng)
Else
dict.Item(header.Value) = dict.Item(header.Value) + WorksheetFunction.CountA(countRng)
End If
Next header
For Each v In dict.Keys
With Worksheets("Sheet2")
.Cells(1, col) = v
.Cells(2, col) = dict.Item(v)
col = col + 1
End With
Next
Set dict = Nothing
End Sub
您的意思是計算非空單元格的數量? –
是的,vba代碼很棒'這正是我需要的。 – Vera
如果它適合你,你能接受答案嗎?它會幫助別人,如果他們正在尋找類似的問題 –