-
Go To Previous Worksheet / Go To Next Worksheet {Problem}
Hi there, I am trying to create a macro button which moves between specified worksheets. The scope of the macro is to move between worksheets and when the last worksheet has been chosen a vbExclamation will pop up telling the user that he cannot go forward anymore.
The macro is working fine and is moving through worksheets as needed, until it comes to the last worksheet and a debug error pops up.
Any help would be appreciated!
{Code as follows}
Sub Forward()
Call PreFunction
Dim SheetNum, SheetLen As Integer
Dim FindNum, NextPg As Variant
SheetNum = CInt(Right(ActiveSheet.Name, 1))
Set FindNum = Sheets("Check").Range("B:B").Find(SheetNum, LookAt:=xlWhole)
NextPg = Sheets("Check").Range(FindNum.Address).Offset(1, 0).Value
SheetLen = Len(ActiveSheet.Name) - 1
If NextPg < SheetNum Then
MsgBox "You cannot go forward from this page!", vbExclamation
ElseIf Sheets(NextPg).Visible = False Then
MsgBox "You cannot go forward from this page!", vbExclamation
Else
Sheets(Left(ActiveSheet.Name, SheetLen) & NextPg).Select
End If
Call PostFunction
End Sub
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules