Excel formula for the number of merged cells?
Consider this little UDF (User Defined Function):
Public Function MergeSize(r As Range) As Long
MergeSize = r(1).MergeArea.Cells.Count
End Function
If the UDF returns 1 , the cell stands alone!
Custom Functions (UDFs) are very easy to install and use:
- ALT-F11 opens VBE window
- ALT-I ALT-M opens a new module
- paste content and close VBE window
If you save the workbook, the UDF will be saved with it. If you are using a version of Excel later than 2003, you must save the .xlsm file and not the .xlsx
To remove the UDF:
- bring up the VBE window as above
- clear code
- close VBE window
To use UDF from Excel:
= MergeSize (A1)
To learn more about macros in general, see
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
and for UDF features:
https://web.archive.org/web/www.cpearson.com/excel/WritingFunctionsInVBA.aspx
Macros must be enabled for this!
source to share
Using the offset function can help in a situation where you have data in a column to the left (or below), this formula counts the number of filled cells at a given distance from the merged cells.
Try this = COUNTA (OFFSET ('[merged range of cells], 0, -1))
-1 moves the counter one column to the left if there was data below the final it would be 1.0)
if there are only cells of spaces around, try the formula
= COUNTBLANK (OFFSET ('[merged cell range], 0, -1))
if there is a mixture of empty and filled cells add formulas together
source to share