Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: How does VBA determine the 1st visible ws?

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    Clovis, NM
    Posts
    341
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Several macros determine which worksheets are visible or hidden. I would like for the macro to end with the first sheet selected (active, visible on screen, not sure of terminology). First means the leftmost tab (of visible sheets) in the order I have them which is not alphabetical and not in sheet number order either.

    All I can think of is to use a bunch (more than would ever be needed) of
    ActiveSheet.Previous.Select
    but there has to be a better way.

  2. #2
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Dim i As Integer
    Do
    i = i + 1
    On Error Resume Next
    Worksheets(i).Select
    Loop Until Worksheets(i).Visible = True


    Will select the first visible worksheet.

    _________________
    Hope this helps.
    Kind regards, Al.

    [ This Message was edited by: Al Chara on 2002-04-09 07:11 ]

  3. #3
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Pilot

    Not too sure I have understood but try this:

    Code:
    Dim iSheet As Integer
    
        For iSheet = 1 To Worksheets.Count
            If Sheets(iSheet).Visible = True Then
               Sheets(iSheet).Select
               Exit For
            End If
        Next iSheet

  4. #4
    Board Regular
    Join Date
    Feb 2002
    Location
    Clovis, NM
    Posts
    341
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    You both understood it fine. Thanks

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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