View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jacob Skaria Jacob Skaria is offline
external usenet poster
 
Posts: 8,520
Default Beginner problem trying to iterate through a selection

Please try this..

Sub Test()
For Each Row In Selection
ActiveCell.Offset(1, 0).Activate
Next
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Steve" wrote:


In Excel 2007, in tracing a problem I was having with a script, I distilled
an issue down to the following:

---------------------------------------------

Sub Test()

For Each Row In Selection

ActiveCell.Offset(0, 1).Activate
ActiveCell.Offset(1, -1).Activate

Next


End Sub

---------------------------------------------


If I select a 2x2 range of cells, what I expect is that when stepping
through the above code, it changes the focus of the selection from (using
these as relative references to the selected range) A1 to A2 to B1 to B2 and
then exiting the script.

However, it does not update the row it thinks it's working on until it goes
through it twice. Which means that for a selection that's 2 rows high, it
loops 4 times, instead of 2.


What am I doing wrong?