• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

for each cell in range - work by row or by column

GeorgeF211

New Member
Hi all,


in VBA, the statement


Code:
For Each Cell In Range

is used quite a bit.  My question is, does this function cycle through by row or by column, i.e. for the range A1:B3 would it work through in the order


[code]a1, a2, a3, b1, b2, b3

or

a1, b1, a2, b2, a3, b3[/code]

I'm sure this is something that is pretty common knowledge, but I can't seem to find an answer on the internet (search criteria for this kind of thing are hard, so it could be I'm not trawling correctly).


Thanks,


George
 
Hi George ,


Try this and see :

[pre]
Code:
Public Sub ForEach()
For Each cell In Selection
MsgBox cell.Address
Next
End Sub
[/pre]
Select your range before you run this macro.


Narayan
 
Cheers Narayank, it's always best to have someone show you how to find something out rather than hold your hand.


Useful thing to know as a function too.
 
Narayan


You should Dim the Cell variable


The code should be:

[pre]
Code:
Public Sub ForEach()
Dim cell As Range
For Each cell In Selection
MsgBox cell.Address
Next
End Sub
[/pre]
 
Back
Top