I think I know what Cookie's saying. Word really doesn't have a sensible way to
skip single-cell rows (a common structure in tables) when you need to add a
column to all the non-single-cell rows. This exasperated me for literally years
until I finally wrote an angry macro to handle it, or most of it (see notes &
caveats after macro). The code isn't terribly sleek but it works:
Sub AddColumnToScruffyTable()
Dim t As Table, rngStart As Range, rngEnd As Range, p As Paragraph
Set t = Selection.Tables(1)
' Enable auto-fit (I despise it, but it's needed here)
t.AllowAutoFit = True
' Set or confirm the table's absolute width (see notes)
t.PreferredWidthType = wdPreferredWidthPoints
t.PreferredWidth = InchesToPoints(6.5)
' Mark the table's start & end, to grab onto after it gets julienned
Set rngStart = t.Range.Cells(1).Range
Set rngEnd = t.Range.Cells(t.Range.Cells.Count).Range
' Find the first 12-cell row
t.Range.Cells(1).Select
FindNext12CellRow:
Do Until Selection.Rows(1).Cells.Count = 12
Selection.MoveRight wdCell
Loop
' Separate the 12-cell row from what's above it
Selection.SplitTable
' Laboriously separate the row from what's below it
' creating a one-row table
Selection.MoveDown wdLine
Selection.Cells(1).Range.Select
Selection.Collapse wdCollapseEnd
Selection.MoveLeft wdCharacter, 1
Selection.MoveDown wdLine, 1
' Stop looping if finished
If Selection.Information(wdWithInTable) = False Then GoTo ZapGaps
Selection.SplitTable
' Get back into the 12-cell row
Selection.MoveUp wdLine, 1
' Add the column
' (edit last # on this line dep on where the column needs to go)
' (this example assumes a new 3rd column)
' (to add a column at the far right, end this line after ".Add")
Selection.Tables(1).Columns.Add BeforeColumn:=Selection.Tables(1).Columns(4)
' Resize this one-row table so it matches the rest
Selection.Tables(1).PreferredWidth = InchesToPoints(6.5)
' Jump across the lower gap
Do Until Selection.Information(wdWithInTable) = False
Selection.MoveDown wdLine, 1
Loop
Selection.MoveDown wdLine, 1
' Repeat
GoTo FindNext12CellRow
ZapGaps:
' Close up all the gaps the splitting created
For Each p In ActiveDocument.Range(rngStart.Start, rngEnd.End).Paragraphs
If p.Range.Information(wdWithInTable) = False Then p.Range.Delete
Next
End Sub
Notes:
- Assumes a fixed table width of 6.5" and assumes this width is to be
maintained. Edit the two 6.5's in the code for other situations.
- Doesn't deal with the 3-cell header row at all.
- Doesn't process the last row if it's a 12-cell row.
- Because of the dirty way it "finds" the next 12-cell row, all hell breaks
loose (infinite loop) if the last row doesn't have 12 cells, so make sure it
does, OR or add code to append a dummy 12-cell row first and chop it off afterward.
Hope this helps. I feel your pain....
=====
Mark Tangard
MS Word MVP 2001-2004