#1
|
|||
|
|||
Table with varying columns in each row
I asked a simlar question before : How do I create a single table (called oTbl, for example) with a varying number of column assigned to different rows ?
For example, row 1 has one column; row 2 has four coumns; row 3 has two columns; row 4 has three columns. (Before, I could use : oTbl.Rows(1).Cells.Merge when I only only needed a table with one and two columns in each row; but now I have more column requirements). Thanks ! |
#2
|
||||
|
||||
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] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Can you add percentage (%) columns to a pivot table? | New Daddy | Excel | 2 | 11-23-2013 09:49 PM |
Columns in a Table in 2002 | Moira | Word | 1 | 05-16-2013 03:23 PM |
Word table - how do I append % symbol to each value in columns 3 & 4 of a table | Dawsie | Word | 4 | 03-06-2013 12:33 AM |
Making Table from Text with Many Columns | SQLUSA | Word | 14 | 07-31-2012 04:26 AM |
How to sort table having three columns? | Bahir Barak | Word | 2 | 01-20-2011 01:52 PM |