Creating a macro to merge cells

J

joão

Hi,

i have a table that has three rows on top and after the
third row has three cells on each row.
I'm trying to create a macro that deletes the content of
the middle cell of each row and merges it with the right
cell.
I want to do this for each row of the table (I don't know
the size of the table), so in the end I only have two
colums (after the first three rows).


Anyone has a light to help me building this kind of cycle?

Thanks a lot,

João
 
J

Jay Freedman

Hi João,

Try this:

Sub TableCrunch()
Dim oTbl As Table
Dim oRow As Row
For Each oTbl In ActiveDocument.Tables
With oTbl
For Each oRow In oTbl.Rows
If oRow.Index > 3 Then
' deleting the range of cell 2
' ensures that the total width
' of the row stays the same,
' where deleting the cell itself
' would make it narrower
oRow.Cells(2).Range.Delete
oRow.Cells.Merge
End If
Next oRow
End With
Next oTbl
End Sub

The .Merge method automatically inserts a paragraph mark between the
contents of cells 1 and 3 to replace the cell marker of cell 1. You may need
to remove this paragraph mark afterward.
 

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