How does VBA determine the 1st visible ws?

pilot

Active Member
Joined
Feb 17, 2002
Messages
345
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.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,620
Messages
6,120,559
Members
448,970
Latest member
kennimack

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top