Search code examples
excelvba

Get first selected cell in a range


When selecting a range in Excel manually, the first cell, or starting cell, of the selection has a different appearance. It does not have a gray layer over it like the rest of the cells in the selection.

Example 1

Example 2

I want to know the following: Is it possible to determine what the starting cell of a selection is using VBA?

If this is possible it would go into the Private Sub Worksheet_SelectionChange(ByVal Target As Range)


Solution

  • Selection.Address will contain the total selected range - from top left to bottom right.

    ActiveCell.Address will have the cell that was the 'start' of the selection.

    You can just refer to these in the event handler:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Debug.Print Selection.Address
        Debug.Print ActiveCell.Address
    End Sub