Merge specific cells in a table

V

vicenflor

I have inserted a table with 5 rows en 17 columns using a macro. Now I want
to merge certain cells, for example : I n row1, I want to merge cells 1 to 5.
And in row 2, I want to merge cells 2 to cell 5. and further. I know in
advance which cells from a particular row need to be merged.

Is there some VBA code for this?

Thanks for the contribution
 
D

Doug Robbins

The following adds such a table at the location of the selection and then
merges those cells:

Dim mytable As Table, myrange As Range
Set mytable = ActiveDocument.Tables.Add(Range:=Selection.Range, NumRows:=17,
NumColumns:=5)
Set myrange = mytable.Cell(1, 1).Range
myrange.End = mytable.Cell(1, 5).Range.End
myrange.Cells.Merge
Set myrange = mytable.Cell(2, 2).Range
myrange.End = mytable.Cell(2, 5).Range.End
myrange.Cells.Merge



--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
V

vicenflor

Thanks Doug,
The code runs fine!

Doug Robbins said:
The following adds such a table at the location of the selection and then
merges those cells:

Dim mytable As Table, myrange As Range
Set mytable = ActiveDocument.Tables.Add(Range:=Selection.Range, NumRows:=17,
NumColumns:=5)
Set myrange = mytable.Cell(1, 1).Range
myrange.End = mytable.Cell(1, 5).Range.End
myrange.Cells.Merge
Set myrange = mytable.Cell(2, 2).Range
myrange.End = mytable.Cell(2, 5).Range.End
myrange.Cells.Merge



--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
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