Detect merged cells in VBA Excel with MergeArea

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

I'm having quite an issue with this one - I have to detect horizontally and vertically merged cells from an excel table. I have to store the first cell coords, and the lenght of the merged area. I iterate through the table with two for-cycles, line by line.

How can I use MergeArea property to detect the merged and non-merged areas? If the cell is not merged, it should probably return empty range, however, this:

"If currentRange Is Nothing Then"

is not working at all. Any ideas? Thanks a lot.

回答1:

There are several helpful bits of code for this.

Place your cursor in a merged cell and ask these questions in the Immidiate Window:

Is the activecell a merged cell?

? Activecell.Mergecells  True 

How many cells are merged?

? Activecell.MergeArea.Cells.Count  2 

How many columns are merged?

? Activecell.MergeArea.Columns.Count  2 

How many rows are merged?

? Activecell.MergeArea.Rows.Count   1 

What's the merged range address?

? activecell.MergeArea.Address   $F$2:$F$3 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!