Select Cells Macro

A

AA

I don't like to take my hands off the keyboard, even to reach for the
cursor pad. So I have four macros: Up, Down, Right, and Left assigned
to Ctrl-k, Ctrl-i, Ctrl-l, and Ctrl-j.

I'd like to be able to select cells the same way, the equivalent of
Shift-Up, Shift-Down, Shift-Right, and Shift-Left. When I record a
macro to do Shift-Right for example, and assign it to Ctrl-Shift-l, all
it will do is select one cell to the right plus the initial cell.
I want it to continue to select to the right if I press Ctrl-Shift-l
again:

Sub SelRight()
'
' SelRight Macro
'
' Keyboard Shortcut: Ctrl+Shift+L
'
ActiveCell.Range("A1:B1").Select
End Sub

What am I missing?

TIA,

Andy
 
J

JE McGimpsey

One way:

Public Sub SelRight()
On Error Resume Next 'can't extend past col IV
With Selection
.Resize(, .Columns.Count + 1).Select
End With
End Sub

Public Sub SelExtendLeft()
On Error Resume Next 'can't extend past col A
With Selection
.Offset(, -1).Resize(, .Columns.Count + 1).Select
End With
On Error GoTo 0
End Sub
 
A

AA

One way:
Public Sub SelRight()
On Error Resume Next 'can't extend past col IV
With Selection
.Resize(, .Columns.Count + 1).Select
End With
End Sub

Public Sub SelExtendLeft()
On Error Resume Next 'can't extend past col A
With Selection
.Offset(, -1).Resize(, .Columns.Count + 1).Select
End With
On Error GoTo 0
End Sub

That's two ways, and they both work. Thanks!!!!!

I thought I could figure out how to extend the selection up and down
by just replacing ".Columns" with ".Rows", but it doesn't work, and I
couldn't make sense out of VBA help.

Any chance you could beam me those two, up and down, also?

TIA,

Andy
 
J

JE McGimpsey

One way (to do each):

Public Sub SelExtendUp()
On Error Resume Next 'can't extend past row 1
With Selection
.Offset(-1, 0).Resize(.Rows.Count + 1).Select
End With
End Sub

Public Sub SelExtendDown()
On Error Resume Next 'can't extend past row 65536
With Selection
.Resize(.Rows.Count + 1).Select
End With
End Sub


[QUOTE="AA said:
One way:

Public Sub SelRight()
On Error Resume Next 'can't extend past col IV
With Selection
.Resize(, .Columns.Count + 1).Select
End With
End Sub

Public Sub SelExtendLeft()
On Error Resume Next 'can't extend past col A
With Selection
.Offset(, -1).Resize(, .Columns.Count + 1).Select
End With
On Error GoTo 0
End Sub

That's two ways, and they both work. Thanks!!!!!

I thought I could figure out how to extend the selection up and down
by just replacing ".Columns" with ".Rows", but it doesn't work, and I
couldn't make sense out of VBA help.

Any chance you could beam me those two, up and down, also?

TIA,

Andy
[/QUOTE]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top