Assign new shortcut to tab through worksheets

jcoop3r

New Member
Joined
Apr 5, 2011
Messages
1
Hi message board,

I would like to assign the function of tabbing through worksheets to CTRL + Right / Left. I know this is already possible with CTRL + Page up / down, but I want to make life easier for myself =)

Any ideas? I can use VBA script so a technical answer is fine

Regards,

James
 

Some videos you may like

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Damon Ostrander

MrExcel MVP
Joined
Feb 17, 2002
Messages
4,239
Hi James,

I assume you mean Ctrl-Right Arrow, etc. You can do this using the following code:

Code:
Sub ActivateWorksheetToRight()
   If ActiveSheet.Index < Sheets.Count Then
      Sheets(ActiveSheet.Index + 1).Activate
   End If
End Sub

Sub ActivateWorksheetToLeft()
   If ActiveSheet.Index > 1 Then
      Sheets(ActiveSheet.Index - 1).Activate
   End If
End Sub

Sub SetKeys()
   Application.OnKey "^{RIGHT}", "ActivateWorksheetToRight"
   Application.OnKey "^{LEFT}", "ActivateWorksheetToLeft"
End Sub

Sub ResetKeys()
   Application.OnKey "^{RIGHT}"
   Application.OnKey "^{LEFT}"
End Sub

First, run the SetKeys macro. This assigns the Ctrl-Right and Left arrow key sequences to the two macros. When you are done and want to return the Ctrl-Right and Left arrow keystrokes to their default settings run the ResetKeys macro.

Of course, you can use this method to set just about any keystrokes to accomplish the page tabbing. I personally use Ctrl-Right and Left arrows quite a bit as I find their default functions to be quite useful, so I would be inclined to instead use something like Ctrl-+ and Ctrl-- (Control Plus and Control Minus) for the page tabbing.

Keep Excelling.

Damon
 

Watch MrExcel Video

Forum statistics

Threads
1,114,652
Messages
5,549,209
Members
410,905
Latest member
Extjel
Top