![]() |
![]() |
|
|||||||
| 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: Apr 2002
Location: NSW. Australia
Posts: 64
|
I have created the following macro that cycles through the sheets in a workbook.
Private Sub cmdAddandExit_Click() ActiveSheet.Next.Select End Sub This macro works fine until it gets to the last sheet then it returns an error. What I want to do is set up an error trapping code that sends it back to sheet 2 when it reaches sheet 40. I tried using the following code but it does not work. Private Sub cmdAddandExit_Click() If ActiveSheet.Sheet40.Active Then ActiveSheet.Sheet02.Select Else ActiveSheet.Next.Select End If End Sub I also tried variations on line 2 If ActiveSheet.Sheet40 Then If ActiveSheet = Sheet40 Then Can anyone help? Thanks in advance |
|
|
|
|
|
#2 |
|
Legend
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
|
Try the following:
Code:
Private Sub cmdAddandExit_Click() On Error GoTo 1 ActiveSheet.Next.Select End 1: Sheets(2).Select End Sub _________________ Cheers, NateO ![]() [ This Message was edited by: NateO on 2002-05-08 14:24 ] |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|