+ Reply to Thread
Results 1 to 5 of 5

Move to next or previous unhidden sheet

  1. #1
    Registered User
    Join Date
    03-29-2011
    Location
    Australia
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    27

    Move to next or previous unhidden sheet

    I have found these two codes for moving to the next/previous visible sheets.

    Please Login or Register  to view this content.
    Sub NextSheet()
    Set Sh = ActiveSheet
    On Error Resume Next
    Do While Sh.Next.Visible <> xlSheetVisible
    If Err <> 0 Then Exit Do
    Set Sh = Sh.Next
    Loop
    Sh.Next.Activate
    On Error GoTo 0
    End Sub

    Sub PrevSheet()
    Set Sh = ActiveSheet
    On Error Resume Next
    Do While Sh.Previous.Visible <> xlSheetVisible
    If Err <> 0 Then Exit Do
    Set Sh = Sh.Previous
    Loop
    Sh.Previous.Activate
    On Error GoTo 0
    End Sub

    Please Login or Register  to view this content.
    I have a workbook with 50 works sheets (some sheets are hidden). I created two command buttons on each sheet (“<Back” and “Next>”) and connected them with relevant codes. It all works well.

    The only issue I have is that when moving from one sheet (say Sheet2) to the next sheet (say Sheet3) I end up in the last active cell in the destination sheet. For example, if the last active cell in Sheet3 was “A23” I will end up in that cell when pressing “Next>” button in Sheet2 or “<Back” button in Sheet4.

    Can anyone assist me to modify these codes so that when moves are made (either to the next or previous unhidden sheet) I always end up in a same destination in each worksheet sheet (say cell “A1”).

    Many thanks in advance

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,167

    Re: Move to next or previous unhidden sheet

    Try putting:

    Please Login or Register  to view this content.

    Just before the End Sub



    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    03-29-2011
    Location
    Australia
    MS-Off Ver
    Excel 2007 & 2010
    Posts
    27

    Re: Move to next or previous unhidden sheet

    Thanks - work perfectly

  4. #4
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,037

    Re: Move to next or previous unhidden sheet

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Never use Merged Cells in Excel

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,037

    Re: Move to next or previous unhidden sheet

    I'm afraid your post does not comply with Rule 8 of our Forum RULES. Cross-posting is when you post the same question in other forums on the web. You'll find people are disinclined to respond to cross-posts because they may be wasting their time solving a problem that has been solved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser)to the cross-post. Expect cross-posts without a link to be closed a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

    Cross-posted: http://www.mrexcel.com/forum/excel-q...den-sheet.html

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1