How to insert an "X" in a selection of several cells?

J

Jed

Hello,
I would like to know how to insert an "X" in all cells selected in a table?
I've tried this :
Selection.TypeText Text:="X"

But this code just put only one "X" in a selection of 6 cells !!!
I'ld like to have a "X" in all 6 cells. These cells are to be selected a
differents places in the table.

Thanks for any advice.

Jed
 
D

Doug Robbins - Word MVP

Dim oCell As Cell

For Each oCell In Selection.Range.Cells
oCell.Range.Text = "X"
Next oCell


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
L

Lene Fredborg

Doug,

I also first made a solution like yours but I found that the Xs do not
always end only where intended. For example, if you have 2 columns and select
only cells in the second column, X's will also appear in the first column
(all cells with an index number from the first in the selection to the last
in the selection will be included). This does not happen if Selection.Cells
is used instead of Selection.Range.Cells:

Dim oCell As Cell

For Each oCell In Selection.Cells
oCell.Range.Text = "X"
Next oCell

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 
G

Greg Maxey

Doug/Lene,

I guess I read the post as the user wanted to put an "X" in each selected
cell and those cells might be discontinuous selection. In which case
neither method seems to work and I can't offer one that does :-(
 
J

Jed

Hello everyone
I'ld like to thanks everyone who response.
I've tested both methods and now I'll continue working on it.
I just want to do something simple and both works well in my case.
So thanks to you all.
I'm using :
Dim oCell As Cell

For Each oCell In Selection.Cells
oCell.Range.Text = "X"
Next oCell
which works fine and I don't have any discontinous select.

Thanks a lot to u all.
My life is more easy now ;-)
 
D

Doug Robbins - Word MVP

Yes, it appears that Selection.Range.Cells is a range that commences with
the first selected cell and then includes every cell in the table between
that cell and the last selected cell in the same way as the cells selection
moves through the table by using the tab key.

If the centre column of a 3 column table is selected, the X gets inserted
into all of the cells except for the first one on the first row and the last
one on the last row.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top