Determining the type of selected range : Selection « Excel « VBA / Excel / Access / Word






Determining the type of selected range

 
Sub Main()
   Debug.Print AreaType(Selection)
End Sub

Function AreaType(RangeArea As range) As String
'   Returns the type of a range in an area
    Select Case True
        Case RangeArea.Count = 1
            AreaType = "Cell"
        Case RangeArea.Count = Cells.Count
            AreaType = "Worksheet"
        Case RangeArea.Rows.Count = Cells.Rows.Count
            AreaType = "Column"
        Case RangeArea.Columns.Count = Cells.Columns.Count
            AreaType = "Row"
        Case Else
            AreaType = "Block"
    End Select
End Function

 








Related examples in the same category

1.Get the address of selection
2.Is the current selection a Range
3.Returns a count of all cells in a selection: using the Selection and Count properties
4.Returns a count of the number of rows in a selection
5.Returns a count of the number of columns in a selection
6.Counts columns in a multiple selection
7.To add a range name based on a selection
8.Get selection address
9.Toggling a Boolean property
10.Selection move down
11.Code does / does not use With-End With
12.Find next heading