PDA

View Full Version : Solved: I'm not understanding why these loops are working in the opposite direction



frank_m
03-06-2011, 07:42 PM
Edited and swapped the loop result descriptions twice
I'm confused and need more rest I guess. Or more coffee :bug:

What is different in these two loops?

this loop reports as I would expect (from Cell A1 to the last row in Col A)
For Each aCell In Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row - 1)

MsgBox aCell.Row

Next
Why is this looping technique reporting the last row number first :doh:
For X = 0 To Range("A" & Rows.Count).End(xlUp).Row - 1

MsgBox X

Next

frank_m
03-06-2011, 08:05 PM
Another Correction to my comments: Both loops are starting from the last row and working their way up.
What am I not realizing ?

GTO
03-07-2011, 03:22 AM
Greetings Frank,

With data down to (inclusive) A28, they both loop from low to high, ending at 27, due to .Row - 1.

Mark

frank_m
03-07-2011, 06:11 AM
Hi Mark,

Thanks for testing it, rather than just reporting to me that I'm crazy.

I had declining cell values that I was confusing with row numbers. -- That combined with not not enough sleep :whistle:

GTO
03-07-2011, 06:51 AM
Trust me, I am most empathetic. I've been on graves for the past year; words for which I could not use here...:deepsleep