[英]How can I count cells in a row but only count adjacent cells once in Excel
只需遍歷范圍內的單元格,注意單元格是否已填充的變化。
Function countActivityBlock(rng As Range) As Long
Dim r As Range, bNum As Boolean
If Not IsEmpty(rng.Cells(1)) Then
bNum = True
countActivityBlock = 1
End If
For Each r In rng
If Not IsEmpty(r) And Not bNum Then
bNum = Not bNum
countActivityBlock = countActivityBlock + 1
ElseIf IsEmpty(r) And bNum Then
bNum = Not bNum
End If
Next r
End Function
SpecialCells(xlCelltypeConstants,xlNumbers)在UDF中不起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.