checks the number of rows and columns in the selection. : Document Selection « Word « VBA / Excel / Access / Word






checks the number of rows and columns in the selection.

 
Sub num()
    With Selection
        If .Columns.Count > 1 And .Rows.Count > 1 Then
            MsgBox "Please select cells in only one row " _
                & "or only one column."
            End
        Else
            If .Cells.Count > 1 Then
                If .Columns.Count > 1 Then
                    .Cells.Delete ShiftCells:=wdDeleteCellsShiftUp
                Else
                    .Cells.Delete ShiftCells:=wdDeleteCellsShiftLeft
                End If
            Else
                .Cells.Delete ShiftCells:=wdDeleteCellsShiftLeft
            End If
        End If
    End With
End Sub

 








Related examples in the same category

1.Using a variable named curSel to restore the selection it collapses, unless collapsing the selection leaves the selection at an end-of-row marker
2.Move Selection left
3.wdStartOfRangeColumnNumber returns the number of the column in which the beginning of the selection or range falls.