![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Houston, TX
Posts: 303
|
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 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Monterrey, Mexico
Posts: 1,433
|
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 |
|
Banned
Join Date: Feb 2002
Posts: 1,582
|
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 |
|
Board Regular
Join Date: Feb 2002
Location: Houston, TX
Posts: 303
|
You both understood it fine. Thanks
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|