View Single Post
  #1   Report Post  
Posted to microsoft.public.word.tables,microsoft.public.word.vba.general
Ed
 
Posts: n/a
Default VBA: For Each Cell in Range jumps out of range?

I have selected four cells in a single column and set a range to them. Then
I want to iterate through each cell of the range. The first pass works
fine, and affects the top cell of the selected cells. The next pass,
though, affects the cell to the right of the top cell, which is not supposed
to be included in the range! Why does this jump out of the range I've set?

Ed

Dim rng As Range
Dim cll As Cell
Set rng = Selection.Range
rng.HighlightColorIndex = wdBrightGreen
' Highlight affects only selected cells,
' indicating range is set properly.
For Each cll In rng.Cells
' Do Stuff
Next cll