Reply
 
Thread Tools Display Modes
  #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


  #2   Report Post  
Posted to microsoft.public.word.tables,microsoft.public.word.vba.general
Jay Freedman
 
Posts: n/a
Default For Each Cell in Range jumps out of range?

Hi Ed,

I'm not sure where (if anywhere) this is documented, but you can't assign a
table column to a range. A Word range always starts in the first cell and
goes left to right to the end of the row, then to the first cell in the next
row and across -- just like the order you'd see if you tabbed from cell to
cell. The column of cells, if you could assign it, would be seen as a
discontinuous series of subranges, something VBA doesn't support. The user
interface does some magic to let you select a column, but VBA doesn't get
the use of that.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Ed wrote:
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



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

Thanks, Jay. Now I seem to remember being told that over a year ago, but
when you don't use it, you lose it.
I appreciate the boost.
Ed

"Jay Freedman" wrote in message
...
Hi Ed,

I'm not sure where (if anywhere) this is documented, but you can't assign

a
table column to a range. A Word range always starts in the first cell and
goes left to right to the end of the row, then to the first cell in the

next
row and across -- just like the order you'd see if you tabbed from cell to
cell. The column of cells, if you could assign it, would be seen as a
discontinuous series of subranges, something VBA doesn't support. The user
interface does some magic to let you select a column, but VBA doesn't get
the use of that.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup

so
all may benefit.

Ed wrote:
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





Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Print Preview a Page Range Jack Page Layout 2 January 5th 06 01:58 AM
cell marker missing - can not type text into cell Mary Smith 360 Tables 1 December 20th 05 05:04 AM
cell's background color not printed correctly [email protected] Tables 2 December 19th 05 12:44 PM
How to wrap text from cell to cell in a table. Jon Coulson Tables 2 August 8th 05 09:12 PM
Paste a range of Excel cells into Word as a link, cell outlines vi Sam Page Layout 1 July 31st 05 02:20 AM


All times are GMT +1. The time now is 05:17 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"