Get start range and end range of a vertically merged cell with Excel using VBA

前端 未结 6 907
有刺的猬
有刺的猬 2020-12-10 13:02

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

Let\'s say I merge Cells B2 down to B50.
How can I get in VBA the start cell(=B

6条回答
  •  盖世英雄少女心
    2020-12-10 13:25

    If you want the cell references as strings, you can use something like this, where Location, StartCell, and EndCell are string variables.

    Location = Selection.Address(False, False)
    Colon = InStr(Location, ":")
    If Colon <> 0 Then
        StartCell = Left(Location, Colon - 1)
        EndCell = Mid(Location, Colon + 1)
    End If
    

    If you want to set them as ranges, you could add this, where StartRange and EndRange are Range objects.

    set StartRange = Range(StartCell)
    set EndRange = Range (EndCell)
    

提交回复
热议问题