Select column cells to the left/right of active selection - an example
Here is another useful tip:
An alternative would be to hold down the shift key and click in the cell to
which you want to extend the selection.
This would minimize the need of having to go to Tools=Macro=Macros and
running this macro or using a shortcut key combination, figuring out the
number of columns left or right you want to go and making sure you included
the negative sign if going to the left, entering that information in an
input box and clicking the OK button. If bad mouse skills cause too much to
be selected, clicking in the original cell and trying again will work. If
you select short of the desired mark, continue to hold the shift key and try
again.
If code is desired, this is more compact:
Sub RangeSelectionOffset()
'Selects column cells to the left or the right of the
'active selection(s). This VBA Procedure can work
'on non-contiguous ranges.
'You are prompted for the column number offset either left (-)
'or right (+).
Dim AddressOffset1 As Range
Dim ColumnOffsetNumber As Integer
On Error Resume Next
Set AddressOffset1 = ActiveCell(1)
ColumnOffsetNumber = Application.InputBox( _
prompt:="Enter # of columns to offset " & vbNewLine & _
"select. Remember a positive (+) value " & vbNewLine & _
"SELECTS TO THE RIGHT, a negative (-) " & vbNewLine & _
"value SELECTS TO THE LEFT.", _
Title:="Select Rows To The Left(-) or The Right(+)", _
Default:=-1, Type:=1) 'type 1 is Number
'Test for a negative (-) column offset number
If ColumnOffsetNumber < 0 Then
Set AddressOffset1 = AddressOffset1 _
.Offset(0, ColumnOffsetNumber)
End If
AddressOffset1.Resize(1, _
Abs(ColumnOffsetNumber) + 1).Select
End Sub
--
Regards,
Tom Ogilvy
|