PC Review


Reply
Thread Tools Rate Thread

Can a For statement work in reverse (from 40 to 1)

 
 
PCLIVE
Guest
Posts: n/a
 
      17th Jan 2008
Is there a way to use a For statement in reverse?
For example:

For i = Sheets.Count To 4
Sheets(i).Activate
Next i

Instead of starting at sheet 4 and working up to the number of sheets in the
workbook, I'd like to start on the last sheet of the workbook and work back
to sheet 4. Is this possible?

The reason I want to do this is because based on certain criteria, I may be
deleting that sheet. Once that happens the sheet numbers get thrown off and
I end up missing some sheets and then possibly getting an error near the end
of the code when it tries to view sheets that don't exist.

Thanks in advance.
Paul


--



 
Reply With Quote
 
 
 
 
John Bundy
Guest
Posts: n/a
 
      17th Jan 2008
For i = 4 To Sheets.Count step-1

--
-John
Please rate when your question is answered to help us and others know what
is helpful.


"PCLIVE" wrote:

> Is there a way to use a For statement in reverse?
> For example:
>
> For i = Sheets.Count To 4
> Sheets(i).Activate
> Next i
>
> Instead of starting at sheet 4 and working up to the number of sheets in the
> workbook, I'd like to start on the last sheet of the workbook and work back
> to sheet 4. Is this possible?
>
> The reason I want to do this is because based on certain criteria, I may be
> deleting that sheet. Once that happens the sheet numbers get thrown off and
> I end up missing some sheets and then possibly getting an error near the end
> of the code when it tries to view sheets that don't exist.
>
> Thanks in advance.
> Paul
>
>
> --
>
>
>
>

 
Reply With Quote
 
PCLIVE
Guest
Posts: n/a
 
      17th Jan 2008
Thanks John. That's good to know for future use. However, I ended up using
a DoWhile loop and subtracting 1 each time. The outcome is the same, but
I'm sure using "step-1" would look better. I may end up reworking my code
with this.

Thanks again.
Paul

--

"John Bundy" <(E-Mail Removed)(remove)> wrote in message
news:5FCEB1A5-06F0-4A40-B62C-(E-Mail Removed)...
> For i = 4 To Sheets.Count step-1
>
> --
> -John
> Please rate when your question is answered to help us and others know what
> is helpful.
>
>
> "PCLIVE" wrote:
>
>> Is there a way to use a For statement in reverse?
>> For example:
>>
>> For i = Sheets.Count To 4
>> Sheets(i).Activate
>> Next i
>>
>> Instead of starting at sheet 4 and working up to the number of sheets in
>> the
>> workbook, I'd like to start on the last sheet of the workbook and work
>> back
>> to sheet 4. Is this possible?
>>
>> The reason I want to do this is because based on certain criteria, I may
>> be
>> deleting that sheet. Once that happens the sheet numbers get thrown off
>> and
>> I end up missing some sheets and then possibly getting an error near the
>> end
>> of the code when it tries to view sheets that don't exist.
>>
>> Thanks in advance.
>> Paul
>>
>>
>> --
>>
>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reverse on even pages in Outlook 2003 does not seem to work =?Utf-8?B?SG9wZVJheQ==?= Microsoft Outlook Calendar 0 12th Nov 2005 02:11 AM
IF Statement won't work Caliban Microsoft Excel Discussion 4 5th Dec 2004 08:03 AM
This statement does not work in VB Tod Microsoft Excel Programming 5 22nd Oct 2004 06:13 PM
Re: Why won't the reverse print order in Word 2000 work for documents. Jay Freedman Microsoft Word Document Management 0 17th Sep 2004 04:48 PM
Why won't the reverse print order in Word 2000 work for documents. =?Utf-8?B?UmljaGFyZCBFbmdsaXNo?= Microsoft Word Document Management 0 17th Sep 2004 03:19 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:11 AM.