[英]Determine range encompassed by merged cells
Given a merged cell in Excel, is it possible to determine with VBA what rows the merged cell includes? 给定Excel中的合并单元格,是否可以使用VBA确定合并单元格包含哪些行? I found this answer , but that only returns the number of cells included in the merged cell; 我找到了这个答案 ,但这只返回合并单元格中包含的单元格数量; I need its start and stop cells (or, in my case, just the row the merged cell starts and stops in; the cell is always only one cell wide). 我需要它的启动和停止单元格(或者,在我的情况下,只是合并单元格开始和停止的行 ;单元格总是只有一个单元格宽度)。
For example, given that cells A1:A5
are merged, and I know that cell A3
is included in that merge, I'd like to be able to programatically get 1
(start) and 5
(stop). 例如,假设单元格A1:A5
合并,并且我知道单元格A3
包含在该合并中,我希望能够以编程方式获得1
(开始)和5
(停止)。 I would greatly prefer not to select
the cells, if possible. 如果可能的话,我更愿意不select
细胞。
Try this 尝试这个
Sub Demo()
Dim r As Range
Set r = Range("YourRange")
With r.MergeArea
MsgBox "Merged Range start row = " & .Row & vbNewLine & _
"Merge Range stop row = " & .Row + .Rows.Count - 1
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.