Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ActiveSheet.Next.Select in a loop - how to abort without error?

Status
Not open for further replies.

thanos54321

Programmer
Jan 3, 2005
24
0
0
DK
Hi all,

I'm working on a code that runs through several sheets with the same code. In the end of the loop, there is a code like:

ActiveSheet.Next.Select

Obviosly, this will make the code crash with an error message when there are no more sheets.

What I'd like the code to do is to end without an error message when the ActiveSheet.Next.Select statement is false. This seems rather simple, but for some reason it has eluded me so far. Anybody got time to look at this? Thanks a bunch!

Thanos54321
 
Hi
You could try a slightly different approach, something like

for i = 1 to worksheets.count
worksheets(i).activate
next

But depending on what you actually want to do with the sheets you may not even need to activate of select!

;-)
If a man says something and there are no women there to hear him, is he still wrong? [ponder]
How do I get the best answers?
 
Thanks, both of you, it works fine for me now thanks to you guys :)


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top