Excel

Go To Previous Worksheet / Go To Next Worksheet

Ease of Use

Easy

Version tested with

2000, 2002, 2003 

Submitted by:

lucas

Description:

Buttons from the "forms" toolbar are assigned macro's for forward and back one sheet at a time. 

Discussion:

You wish to navigate through a workbook one sheet at a time and occasionally need to go backwards. The buttons make navigation intuitive for people not familiar with excel sheet tabs. 

Code:

instructions for use

			

Option Explicit Sub GoForth() MoveSheet (1) End Sub Sub GoBack() MoveSheet (-1) End Sub Sub MoveSheet(iMove As Integer) Dim iSheetNum As Integer iSheetNum = ActiveSheet.Index On Error Resume Next Do Err.Clear iSheetNum = iSheetNum + iMove If iMove > 0 Then If iSheetNum > Sheets.Count Then iSheetNum = 1 Else If iSheetNum < 1 Then iSheetNum = Sheets.Count End If Sheets(iSheetNum).Select Loop Until Err.Number = 0 End Sub

How to use:

  1. Go to Tools-Macro-Visual Basic Editor from the main toolbar.
  2. From the insert menu, click on module. Paste the code above into the module.
  3. Save and close the Visual Basic Editor.
  4. From the forms toolbar add a button to the first sheet, right click and assign the sub "GoForth" to the button.
  5. On the next sheet add one button to go back, right click and assign the "GoBack" macro to it. And So on.
 

Test the code:

  1. Click on the buttons to test.
 

Sample File:

previous-next.zip 8.67KB 

Approved by mdmackillop


This entry has been viewed 225 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express