Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
给定 Excel 中的合并单元格,是否可以使用 VBA 确定合并单元格包含哪些行?我找到了这个答案,但这仅返回合并单元格中包含的单元格数;我需要它的开始和停止单元格(或者,在我的情况下,只是合并单元格开始和停止的行;单元格总是只有一个单元格宽)。
例如,假设单元格A1:A5已合并,并且我知道该单元格A3包含在该合并中,我希望能够以编程方式获取1(开始)和5(停止)。如果可能的话,我非常不喜欢select细胞。
A1:A5
A3
1
5
select
试试这个
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