Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-23-2014, 07:26 AM
norwood norwood is offline Table with varying columns in each row Windows Vista Table with varying columns in each row Office 2000
Novice
Table with varying columns in each row
 
Join Date: Sep 2013
Posts: 23
norwood is on a distinguished road
Default 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 !
Reply With Quote
  #2  
Old 05-23-2014, 03:16 PM
macropod's Avatar
macropod macropod is offline Table with varying columns in each row Windows 7 32bit Table with varying columns in each row Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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
Reply



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
Table with varying columns in each row 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
Table with varying columns in each row How to sort table having three columns? Bahir Barak Word 2 01-20-2011 01:52 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:56 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft