<(E-Mail Removed)> wrote...
>The problem is the count remains the same whether or not
>some cells are merged. I'm trying to get a true count of
>all booths: that is occupied single booths + unoccupied
>single booths + occupied merged booths. A merged double
>booth or merged triple booth are each counted as 1.
....
The problem is that there is no simple way to perform calculations on ranges
that include merged cells. They're a feature that, on a superficial level,
appears useful, but when you dig deeper it proves to be far more trouble
than it's worth.
That said, there's a way to do what you want, but it *REQUIRES* using VBA to
write a user-defined function. If using VBA at all or using it to write udfs
is unacceptable, you just can't do what you want to do with merged cells, so
you'll need to stop using them.
Here are two possible udfs.
Function tcount(ParamArray a() As Variant) As Long
Dim x As Variant, y As Variant
Application.Volatile
For Each x In a
If TypeOf x Is Range Then
For Each y In x
If VarType(y.Value) = vbDouble Or VarType(y.Value) = vbDate Then
tcount = tcount + y.MergeArea.Cells.Count
End If
Next y
ElseIf IsArray(x) Then
For Each y In x
If VarType(y) = vbDouble Or VarType(y) = vbDate Then
tcount = tcount + 1
End If
Next y
ElseIf VarType(x) = vbDouble Or VarType(x) = vbDate Then
tcount = tcount + 1
End If
Next x
End Function
Function tcounta(ParamArray a() As Variant) As Long
Dim x As Variant, y As Variant
Application.Volatile
For Each x In a
If TypeOf x Is Range Then
For Each y In x
If Not IsEmpty(y.Value) Then
tcounta = tcounta + y.MergeArea.Cells.Count
End If
Next y
ElseIf IsArray(x) Then
For Each y In x
If Not IsEmpty(y) Then
tcounta = tcounta + 1
End If
Next y
ElseIf Not IsEmpty(x) Then
tcounta = tcounta + 1
End If
Next x
End Function
|