Merged cells


#1

If I have a range of merged cells in a row, how do I find out which cells are in the merged range?



Basically I’m finding certain cells and testing to see if they are
merged or not (IsMerged). If TRUE, I need to find the first and last
cell within the merged range.



How do I do this?


#2

You can use Cell.IsMerged property to check if a cell is merged. And I can provide a property to return all merged cell rectangle area. Will it serve your need?


#3

Hi Lawrence



All merged ranges that I’ll be dealing with with be merged along a row.



I’m using the Cell.IsMerged property.



If the return value is TRUE I need to know the name of the first
(left-most) cell in the merged range, and either the name of the last
(right-most) cell or the number of cells merged in the range.

I’m using code to move through a specific area on the worksheet, so I
will already know the row and column values of the current cell.
Perhaps you could provide me with a way of knowing how many cells are
merged and what cell i’m on within that range i.e. 5 cells merged and
i’m on cell 2 out of 5.



Thanks.


#4

Please try the attached fix. It provides a new Cell.GetMergedRange method.

Range range = cell.GetMergedRange();

if(range != null)

{

......

}

If you call this method, Cell.IsMerged property is not needed.


#5

Thanks!



I’ll let you know how I get on.