Option Explicit
Sub DisplayCorner_Addresses_of_Selection()
' For a given selection, displays the
' 1. Top left cell
' 2. Bottom left cell
' 3. Top right cell
' 4. Bottom right cell
' as String addresses in a MsgBox
Dim TopRow_Selection As Long, BottomRow_Selection As Long, LeftCol_Selection As Long, RightCol_Selection As Long
Dim TopLeftCel_Selection As String, BottomLeftCel_Selection As String, TopRightCel_Selection As String, BottomRightCel_Selection As String
With Selection
Select Case .Cells.Count
Case Is <= 0
GoTo error_handler
Case Else
TopRow_Selection = .Row
BottomRow_Selection = .Rows.Count + .Row - 1
LeftCol_Selection = .Column
RightCol_Selection = .Columns.Count + .Column - 1
TopLeftCel_Selection = Cells(Selection.Row, Selection.Column).Address
BottomLeftCel_Selection = Cells(Selection.Rows.Count + Selection.Row - 1, Selection.Column).Address
TopRightCel_Selection = Cells(Selection.Row, Selection.Columns.Count + Selection.Column - 1).Address
BottomRightCel_Selection = Cells(Selection.Rows.Count + Selection.Row - 1, Selection.Columns.Count + Selection.Column - 1).Address
MsgBox "Top row: " & TopRow_Selection & vbCrLf & "Bottom row: " & BottomRow_Selection & vbCrLf & "Left Column: " & LeftCol_Selection & vbCrLf & "Right column: " & RightCol_Selection & vbCrLf & vbCrLf & "Top Left Cell: " & TopLeftCel_Selection & vbCrLf & "Bottom Left Cell: " & BottomLeftCel_Selection & vbCrLf & "Top Right Cell: " & TopRightCel_Selection & vbCrLf & "Bottom Right Cell: " & BottomRightCel_Selection
End Select
End With
Exit Sub
error_handler:
Call MsgBox("You haven't made a a valid selection of cells:" & vbCrLf & "" _
& vbCrLf & "Please select a SINGLE or MULTIPLE cells and re-run this macro.", _
vbCritical, "Selection Invalid")
End Sub