Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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: 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
 

Thread Tools
Display Modes


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 01:17 PM.


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