Forum Discussion
Vincent Kelly
Aug 29, 2021Copper Contributor
countblank in a range made up of smaller areas
If you have a range of cells (call it MyRange) made up of smaller areas, so that MyRange is never just one 'rectangle' of cells but a few of them (which happen to be adjoining), I find that the funct...
HansVogelaar
Sep 04, 2021MVP
Your sample workbook didnt have merged cells...
Do you mean that you want an empty merged cell to count as 1? The built-in function COUNTBLANK does not do that.
But here is a new version. It will be slow for very large ranges.
Function CountBlankAll(rng As Range) As Long
Dim cel As Range
Dim dct As Object
Dim adr As String
Dim n As Long
Set dct = CreateObject("Scripting.Dictionary")
For Each cel In rng
If cel.MergeCells Then
adr = cel.MergeArea.Address
Else
adr = cel.Address
End If
If Not dct.Exists(adr) Then
dct.Add Item:=Null, Key:=adr
If cel.Value = "" Then
n = n + 1
End If
End If
Next cel
CountBlankAll = n
End Function
Vincent Kelly
Sep 05, 2021Copper Contributor
Hans, You know your stuff! Sorry about that omission (merged cells) - my mistake. Your amended function works perfectly! Thank you,
Vincent Kelly
Vincent Kelly