vba 如何在VBA中查找范围是否包含合并的单元格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28479611/
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
How to find if range contains merged cells in VBA
提问by Berker Yüceer
I have an Excel document that contains duty shifts. I would like to findout if there is any merged cells like given below withing given range..
我有一个包含值班的 Excel 文档。我想找出在给定范围内是否有任何如下所示的合并单元格..
How can I determine the cells are filled in given range or the cells are merged in given range?
如何确定在给定范围内填充单元格或在给定范围内合并单元格?
If IsEmpty(Range("NewRange")) = False Then
z = z + 1 'My counter
End If
I tried IsEmpty Function but it doesnt work correctly on merged cells. You can try but the result is same.. While I got a block of empty cells there it counts as filled..
我尝试了 IsEmpty 函数,但它在合并的单元格上无法正常工作。你可以试试,但结果是一样的..虽然我在那里得到了一块空单元格,但它算作已填满..
回答by Maciej Los
MS Excel 2010 and higher has Range.MergeCells Property (Excel), which returns trueif if the range contains merged cells.
MS Excel 2010 及更高版本具有Range.MergeCells 属性 (Excel),如果该区域包含合并的单元格,则返回true。
Another method you'll find here: http://www.exceltrick.com/how_to/find-merged-cells-in-excel/
您可以在这里找到另一种方法:http: //www.exceltrick.com/how_to/find-merged-cells-in-excel/
Dim r As Range
Set r = Range("A9:G10")
With r
If IsNull(.MergeCells) = True Or .MergeCells = True Then
z = z + 1
End If
End With