Home |
Search |
Today's Posts |
#1
|
|||
|
|||
Word.mailmerge.tableformat.groupbyfield
Is it possible to create a table using a merge and group by company name as a
column header (5 columns 2 rows to the table) and list individuals of that company in the cell below the column header then advance to the next column for a new company name? Company 1 name Company 2 Name Company 3 Name person one person one person one person two person two person two |
#2
|
|||
|
|||
If you create a catalog (or in Word XP and later, a directory) type
mailmerge, you could probably run a modified version of the following macro over the document created by executing that mailmerge to achieve what you are after. ' Macro to create multiple items per condition in separate tables from a directory type mailmerge Dim source As Document, target As Document, scat As Range, tcat As Range Dim data As Range, stab As Table, ttab As Table Dim i As Long, j As Long, k As Long, n As Long Set source = ActiveDocument Set target = Documents.Add Set stab = source.Tables(1) k = stab.Columns.Count Set ttab = target.Tables.Add(Range:=Selection.Range, numrows:=1, numcolumns:=k - 1) Set scat = stab.Cell(1, 1).Range scat.End = scat.End - 1 ttab.Cell(1, 1).Range = scat j = ttab.Rows.Count For i = 1 To stab.Rows.Count Set tcat = ttab.Cell(j, 1).Range tcat.End = tcat.End - 1 Set scat = stab.Cell(i, 1).Range scat.End = scat.End - 1 If scat tcat Then ttab.Rows.Add j = ttab.Rows.Count ttab.Cell(j, 1).Range = scat ttab.Cell(j, 1).Range.Paragraphs(1).PageBreakBefore = True ttab.Rows.Add ttab.Cell(j + 1, 1).Range.Paragraphs(1).PageBreakBefore = False For n = 2 To k Set data = stab.Cell(i, n).Range data.End = data.End - 1 ttab.Cell(ttab.Rows.Count, n - 1).Range = data Next n Else ttab.Rows.Add For n = 2 To k Set data = stab.Cell(i, n).Range data.End = data.End - 1 ttab.Cell(ttab.Rows.Count, n - 1).Range = data Next n End If Next i -- Please respond to the Newsgroup for the benefit of others who may be interested. Questions sent directly to me will only be answered on a paid consulting basis. Hope this helps, Doug Robbins - Word MVP "laschmitz" wrote in message ... Is it possible to create a table using a merge and group by company name as a column header (5 columns 2 rows to the table) and list individuals of that company in the cell below the column header then advance to the next column for a new company name? Company 1 name Company 2 Name Company 3 Name person one person one person one person two person two person two |
#3
|
|||
|
|||
Thank you Doug, however the person that I need to do this for is still using
Office 2000 so I don't think I can create this for her. Or, can I create it in XP and the file be compatible? "Doug Robbins" wrote: If you create a catalog (or in Word XP and later, a directory) type mailmerge, you could probably run a modified version of the following macro over the document created by executing that mailmerge to achieve what you are after. ' Macro to create multiple items per condition in separate tables from a directory type mailmerge Dim source As Document, target As Document, scat As Range, tcat As Range Dim data As Range, stab As Table, ttab As Table Dim i As Long, j As Long, k As Long, n As Long Set source = ActiveDocument Set target = Documents.Add Set stab = source.Tables(1) k = stab.Columns.Count Set ttab = target.Tables.Add(Range:=Selection.Range, numrows:=1, numcolumns:=k - 1) Set scat = stab.Cell(1, 1).Range scat.End = scat.End - 1 ttab.Cell(1, 1).Range = scat j = ttab.Rows.Count For i = 1 To stab.Rows.Count Set tcat = ttab.Cell(j, 1).Range tcat.End = tcat.End - 1 Set scat = stab.Cell(i, 1).Range scat.End = scat.End - 1 If scat tcat Then ttab.Rows.Add j = ttab.Rows.Count ttab.Cell(j, 1).Range = scat ttab.Cell(j, 1).Range.Paragraphs(1).PageBreakBefore = True ttab.Rows.Add ttab.Cell(j + 1, 1).Range.Paragraphs(1).PageBreakBefore = False For n = 2 To k Set data = stab.Cell(i, n).Range data.End = data.End - 1 ttab.Cell(ttab.Rows.Count, n - 1).Range = data Next n Else ttab.Rows.Add For n = 2 To k Set data = stab.Cell(i, n).Range data.End = data.End - 1 ttab.Cell(ttab.Rows.Count, n - 1).Range = data Next n End If Next i -- Please respond to the Newsgroup for the benefit of others who may be interested. Questions sent directly to me will only be answered on a paid consulting basis. Hope this helps, Doug Robbins - Word MVP "laschmitz" wrote in message ... Is it possible to create a table using a merge and group by company name as a column header (5 columns 2 rows to the table) and list individuals of that company in the cell below the column header then advance to the next column for a new company name? Company 1 name Company 2 Name Company 3 Name person one person one person one person two person two person two |