Hi I have an spreadsheet with the following structure:-
I need help to figure out a formula or VBA function, to calculate the Activity Block Count column.
This is the count of non blank, contiguous cells in the date columns. For example Project 5 has 4 weeks of activity but only 3 continuous blocks of activity.
Any idea warmly welcomed ;-). I'm working at the weekend and it's driving me insane!
Thanks
Jonathan
Just walk through the cells in the range, noting changes in whether the cell(s) are populated or not.
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) does not work within a UDF.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.