View Single Post
 
Old 05-23-2014, 03:16 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,523
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

There are numerous ways of going about this. Perhaps the simplest for the table you described is to create a four-row, one-column table, then split each of the 2nd-4th rows into however many cells you want. See Demo1. This will result in a table in which the cell widths on each row are equal. Alternatively, for a table with some cells spanning two-or-more columns, you could start with the four columns then merge the cells concerned. See Demo2.
Code:
Sub Demo1()
Dim wdTbl As Table, i As Long
With ActiveDocument
  Set wdTbl = .Tables.Add(Range:=.Paragraphs.Last.Range, Numrows:=4, NumColumns:=1)
  With wdTbl
    For i = 2 To .Rows.Count
      .Rows(i).Cells(1).Split Numrows:=1, NumColumns:=i
    Next
  End With
End With
End Sub
 
Sub Demo2()
Dim wdTbl As Table, i As Long, Rng As Range
With ActiveDocument
  Set wdTbl = .Tables.Add(Range:=.Paragraphs.Last.Range, Numrows:=4, NumColumns:=4)
  With wdTbl
    For i = 2 To .Rows.Count
      Set Rng = .Rows(i).Cells(i - 1).Range
      With Rng
        .MoveEnd Unit:=wdCell, Count:=1
        .Cells.Merge
      End With
    Next
  End With
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote