2017-04-25 118 views
0

我試圖計算在Excel註釋細胞與這個VBA代碼,但它返回整個工作表所有評論。我如何更改此代碼來計算單元格只在一行或一列中形成n1..n2?如何計算excel中使用VBA的註釋單元格?

Function CountComments(xCell As Range) 

    Application.Volatile 
    CountComments = xCell.Parent.Comments.Count 
End Function 

例如:

A1 = CountComments(G2:G7)

A2 = CountComments(H2:H7)

他們返回一個結果

回答

0

你可以試試這個,它計數有意見的小區的數量

Function CountComments(xCells As Range) 

Dim x As Range 
On Error Resume Next 

For Each x In xCells 
L = -1 
L = Len(x.Comment.Text) 
    If L >= 0 Then Counts = Counts + 1 
Next 

CountComments = Counts 
End Function 
相關問題