vba 确定合并区域的大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1673171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 10:57:02  来源:igfitidea点击:

Determining the size of a merged area

excelvbaoffice-2003

提问by Oxymoron

Right, before we get off about merged cells, I hate them too, but I've to deal with them anyway. I cannot change anything about that now or in the future. As much as I would like to ;)

对,在我们开始讨论合并单元格之前,我也讨厌它们,但无论如何我必须处理它们。我现在或将来都无法改变这一点。尽我所能;)

Say I have some merged cells, I need to determine the amount of cells it spans. Say A1:A4 are merged, then I need to have the number of merged cells, 4, returned. Is there any way to accomplish this?

假设我有一些合并的单元格,我需要确定它跨越的单元格数量。假设 A1:A4 被合并,那么我需要返回合并单元格的数量 4。有什么办法可以做到这一点吗?

回答by Dick Kusleika

ActiveCell.MergeArea.Count

回答by Adriaan Stander

You can use

您可以使用

Dim r As range
Dim i As Integer
    Set r = range("A1")
    i = r.CurrentRegion.Count

This will give A1:A4 as 4, A1:B4 as 8.

这将使 A1:A4 为 4,A1:B4 为 8。