Find Merged Cells in Excel Range and Unmerge
Posted on 2011-03-14
I have some code which does a lot of calculation and generates a matrix as an output. As part of this, each coordinate in the matrix will grow or shrink depending on the number of values within the coordinate (if that makes sense!). For example, The coordinate corresponding to 3C may contain 6 values each of which are held in a separate cell. This then means that anything in the C row will always have at least 6 cells.
That's the bit that I've got working. What I'm struggling with is tidying up the titles. For each row I need to place a title which will be merged down across the cells; so, to use the previous example, if the 3C coordinate values are held in the range "H12:H17" I want to have a title of "C - Solid Performer" which will be merged in the range "D12:D17".
As it happens, I've also got this to work and I can get the titles to merge correctly. However, here is the problem:
If I re-run my function and the number of values in the coordinates differs (which it almost certainly will for each analysis), then the merged titles do not work as the previous merged cells have not cleared. The question is:
1. How do I find merged cells in a range (bearing in mind the range itself will not be static on each running of the code;
2. How do I unmerge the cells when they are found?