使用VBA获取垂直合并单元格的开始范围和结束范围 [英] Get start range and end range of a vertically merged cell with Excel using VBA

查看:1915
本文介绍了使用VBA获取垂直合并单元格的开始范围和结束范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找出垂直合并的单元格的第一个单元格和最后一个单元格。

I need to find out the first cell and the last cell of a vertically merged cell..

让我们将单元格B2合并到B50。

如何在VBA中获取起始单元格(= B2)和结束单元格(= B50)?

Let's say I merge Cells B2 down to B50.
How can I get in VBA the start cell(=B2) and the end cell(=B50)?

推荐答案

Sub MergedAreaStartAndEnd()

    Dim rng As Range
    Dim rngStart As Range
    Dim rngEnd As Range

    Set rng = Range("B2")

    If rng.MergeCells Then

        Set rng = rng.MergeArea
        Set rngStart = rng.Cells(1, 1)
        Set rngEnd = rng.Cells(rng.Rows.Count, rng.Columns.Count)

        MsgBox "First Cell " & rngStart.Address & vbNewLine & "Last Cell " & rngEnd.Address

    Else

        MsgBox "Not merged area"

    End If

End Sub

这篇关于使用VBA获取垂直合并单元格的开始范围和结束范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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