使用MergeArea检测VBA Excel中的合并单元格 [英] Detect merged cells in VBA Excel with MergeArea
问题描述
我有一个这个问题 - 我必须从Excel表中检测水平和垂直合并的单元格。我必须存储第一个单元格的坐标,以及合并区域的长度。我循序渐进地使用两个循环,一行一行。
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.
如何使用MergeArea属性来检测合并和未合并的区域?
如果单元格未合并,则应该返回空白范围,但是:
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
"If currentRange Is Nothing Then"
根本不工作。有任何想法吗?
非常感谢。
is not working at all. Any ideas? Thanks a lot.
推荐答案
这里有几个有用的代码。
There are several helpful bits of code for this.
将光标放在合并的单元格中,并在Immidiate窗口中提出这些问题:
Place your cursor in a merged cell and ask these questions in the Immidiate Window:
合并单元格?
? Activecell.Mergecells
True
有多少个单元格合并?
? Activecell.MergeArea.Cells.Count
2
合并了多少列?
? Activecell.MergeArea.Columns.Count
2
合并了多少行?
? Activecell.MergeArea.Rows.Count
1
合并范围地址是什么?
? activecell.MergeArea.Address
$F$2:$F$3
这篇关于使用MergeArea检测VBA Excel中的合并单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!