Counts columns in a multiple selection : Selection « Excel « VBA / Excel / Access / Word






Counts columns in a multiple selection

 

Sub CountColumnsMultipleSelections()        
    AreaCount = Selection.Areas.Count
    If AreaCount <= 1 Then
        MsgBox "The selection contains " & Selection.Columns.Count & " columns."
    Else
        For i = 1 To AreaCount
            MsgBox "Area " & i & " of the selection contains " & Selection.Areas(i).Columns.Count & " columns."
        Next i
    End If
End Sub

 








Related examples in the same category

1.Get the address of selection
2.Is the current selection a Range
3.Determining the type of selected range
4.Returns a count of all cells in a selection: using the Selection and Count properties
5.Returns a count of the number of rows in a selection
6.Returns a count of the number of columns in a 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