使用 MergeArea 检测 VBA Excel 中的合并单元格 [英] Detect merged cells in VBA Excel with MergeArea

查看:30
本文介绍了使用 MergeArea 检测 VBA Excel 中的合并单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了这个问题 - 我必须从 Excel 表中检测水平和垂直合并的单元格.我必须存储第一个单元格坐标和合并区域的长度.我用两个 for 循环逐行遍历表格.

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:

如果 currentRange 什么都没有"

"If currentRange Is Nothing Then"

根本不起作用.有任何想法吗?非常感谢.

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

推荐答案

为此提供了一些有用的代码.

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

合并了多少个单元格?

? Activecell.MergeArea.Cells.Count
 2

合并了多少列?

? Activecell.MergeArea.Columns.Count
 2

合并了多少行?

? Activecell.MergeArea.Rows.Count
  1

合并的范围地址是什么?

What's the merged range address?

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

这篇关于使用 MergeArea 检测 VBA Excel 中的合并单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆