Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default For...next in reverse

Is it possible to do a for each..next loop through a range in reverse e.g

dim grCell as range

for each grCell in sheets("sheet1").range("A100:A1")
...do something here
next grCell

I've look through the help files but no luck.
Thank you for your time
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default For...next in reverse

try looping with a descending index (i.e. Step -1)

ex.

for i = sheets("sheet1").range("A100:A1").cells.count to 1 Step -1
do something on sheets("sheet1").range("A100:A1").cells(i)
next

-Todd

www.ManagementAnalytics.com

"Rod Jones" wrote:

Is it possible to do a for each..next loop through a range in reverse e.g

dim grCell as range

for each grCell in sheets("sheet1").range("A100:A1")
..do something here
next grCell

I've look through the help files but no luck.
Thank you for your time

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 863
Default For...next in reverse

Not with For Each, but with an "old style" For/Next loop that uses a counter
and the index property:

With Sheets("Sheet1").Range("A1:A100")
For i = .Cells.Count To 1 Step -1
'then one or the other of these constructs:

.Cells(i).ClearContents

'or
Set grCell = .Cells(i)
grCell.ClearContents

Next i
End With

On Tue, 12 Oct 2004 06:19:04 -0700, Rod Jones <Rod
wrote:

Is it possible to do a for each..next loop through a range in reverse e.g

dim grCell as range

for each grCell in sheets("sheet1").range("A100:A1")
..do something here
next grCell

I've look through the help files but no luck.
Thank you for your time


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default For...next in reverse

not really.

you can do

Dim i as long, grCell as Range
for i = 100 to 1 step - 1
set grCell = Sheets("Sheet1").Cells(i,1)

Next

or you can play games

dim grCell as range
Dim rng as Range, grCell1 as Range
set rng = sheets("sheet1").range("A1:A100")
for each grCell in rng
set grCell1 = rng(101 - grCell.row)
...do something here
next grCell

Reversing A1:A100 doesn't do what you want.

--
Regards,
Tom Ogilvy


"Rod Jones" <Rod wrote in message
...
Is it possible to do a for each..next loop through a range in reverse e.g

dim grCell as range

for each grCell in sheets("sheet1").range("A100:A1")
..do something here
next grCell

I've look through the help files but no luck.
Thank you for your time



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
reverse value rb Excel Worksheet Functions 1 March 28th 07 02:51 AM
reverse value Mike Excel Worksheet Functions 0 March 28th 07 12:08 AM
Reverse Sum vjeevar Excel Discussion (Misc queries) 2 February 8th 06 10:04 PM
reverse of concatenate S.G.Pillai Excel Discussion (Misc queries) 4 November 1st 05 12:27 PM
In Reverse... stck2mlon[_13_] Excel Programming 12 June 2nd 04 11:45 PM


All times are GMT +1. The time now is 02:30 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"