Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selectively merge two cells in a Word table

Status
Not open for further replies.

felagund

Technical User
Feb 28, 2008
5
GB
I have a long Word 2000 table (21 pages) consisting of two columns (author and title). Sometimes there is a break for theme, which is listed in the first column. Where a theme occurs, I would like to merge the two columns. So from the example below, I would like to merge the first line only, but keep the rest atomic: This would both shorten and make the table better aesthetically.

Command, Control and Communications
Harris, J.P. with N. Barr Amiens to the Armistice. The BEF in the Hundred Days Campaign 8 August-11 November 1918 (London: Brassey’s, 1999)
Prior, Robin & Wilson, Trevor Command on the Western Front. The Military Career of Sir Henry Rawlinson (Oxford: Blackwell, 1991; Barnsley: Pen & Sword, 2004)

I have already done a search, and was intrigued by thread707-935057. Thanks for reading.
 
Define your requirements in more detail, please.

1. Does it have to remain as a table?
2. Why do you think it would shorten the document?
3. Define your aesthetics. Can it look like a merged cell?

I ask because I am strongly against the use of merged cells in Word tables. There may be a use for them, but IMO they are to be avoided.

faq219-2884

Gerry
My paintings and sculpture
 
Thanks for your reply, I hope this makes things clearer. I am open to ideas, but feel that a table would best serve.

This is roughly what I have:

Code:
Command, 
Control and 
Communications    
Harris, J.P.    Amiens to the Armistice.  The BEF in the with N. Barr    Hundred Days Campaign 8 August-11  
                November 1918 (London: Brassey’s, 1999)
Prior, Robin &  Command on the Western Front.  The Military  
Wilson, Trevor  Career of Sir Henry Rawlinson (Oxford:
   
                Blackwell, 1991; Barnsley: Pen & Sword,2004)

This is what I'd like:

Command, Control and Communications    
Harris, J.P.    Amiens to the Armistice.  The BEF in the with N. Barr    Hundred Days Campaign 8 August-11  
                November 1918 (London: Brassey’s, 1999)
Prior, Robin &  Command on the Western Front.  The Military 
Wilson, Trevor  Career of Sir Henry Rawlinson (Oxford: 
                Blackwell, 1991; Barnsley: Pen & Sword,2004)
If you see, the 'theme' line is not wrapped, but extends across the full width of the table (and I am using the full width of the page. It's both easier on the eye, and more economic. I would save a copy before I merged fields, and could revert back if need be. If merging fields is that problematic, I could live with shifting the content of the first field to the much wider second field (where empty).
 
Just to clarify, you have:

Command,
Control and
Communications
Harris, J.P. Amiens to the Armistice. The BEF in the
with N. Barr Hundred Days Campaign 8 August-11
November 1918 (London: Brassey’s, 1999)
Prior, Robin & Command on the Western Front. The
Wilson, Trevor Military Career of Sir Henry
Rawlinson Oxford: Blackwell, 1991;
Barnsley: Pen & Sword,2004)


with the authors in italics (just for clarity) in one cell each. That is, "Harris, J.P. with N. Barr" is in one cell.

Correct? The same column width has Command, Control and
Communications.

You want Command, Control and Communications across the entire width of the table.

It may help if you actually answered #1 in my previous post.

How about breaking the table up at the theme, making the theme a text heading, keep the entries for that theme in a table (but removing the theme row).

faq219-2884

Gerry
My paintings and sculpture
 
In reply to #1 I have already stated ' I am open to ideas, but feel that a table would best serve.'

Your assumptions are correct, as stated in the original post, the author is in the first column

Prior, Robin &
Wilson, Trevor

Theme occurs in the same column, followed by an empty cell.

If the process of turning the theme rows into text could be automated, that would be fine.

Thanks
 
Well it could be automated, depending on how consistent the document is.

If the "theme" rows are the ONLY rows with empty Column 2, then sure. Have Word run through the table and where it finds something in col1, but nothing in col2, that is a theme. Split the table and use the text in col1 (the theme) as text.

faq219-2884

Gerry
My paintings and sculpture
 
Thanks. The document is consistent. Column 2 is empty where there is a theme. It is the autmation aspect I am having problems with. How do I check for no content in columsn 2? How do I convert such rows to text?
 
First step is looking things up in Help.

Second is looking for previous posted solutions. There was an extensive thread precisely on this subject - splitting tables - here at Tek-Tips, that I posted quite a bit of code for.

Third, one of the more powerful ways to find things out....the macro recorder, and then looking at the code.

I have to point out that the only way is to go through the Row collection in the table. You have 21 pages of a table. It should not be TOO long to run through them. If it was 600 pages.....

Write out the logic. I mean it. Not many people do, but it can really help. Write it out, step-by-step. Something like:

check each row of the table
IF cell 2 of Row is empty THEN
split the table before and after that row
convert that row to text and hopefully attach a style
End IF
check next row

Actually...there you go.



faq219-2884

Gerry
My paintings and sculpture
 
Thanks Gerry, I now have the table exactly as I want it.

I tried to convert rows to text, without success, but the merge worked first time. I was using the help, pseudocode, and macros (this is the way I write macros in Excel), but seemed to be hitting a blank wall. Matching the empty field was a big stumbling block. The thread you alluded to was a big help I eventually found the thread by searching on 'table' - 'splitting tables' didn't seem to produce results. No special formatting or spacing was needed, and a 25 page (not 21 as stated) list has reduced to 17. This is my first thread on this or indeed any Office forum. Thanks for your patience, and sorry if I appeared obtuse.


Sub mcrMergeRow()
Dim var As Long
' Macro recorded 02/03/2008 mjm
Dim objTable As Table, objRow As Row
var = 1
Set aTable = ActiveDocument.Tables(1)
For Each objTable In ActiveDocument.Tables
For Each objRow In objTable.Rows
If aTable.Rows(var).Cells(2).Range.Text = _
Chr(13) & Chr(7) Then
objRow.oCells.Merge
End If
var = var + 1
Next
Next
End Sub
 
Why not simply this ?
Code:
Sub mcrMergeRow()
Dim objTable As Table, objRow As Row
For Each objTable In ActiveDocument.Tables
  For Each objRow In objTable.Rows
    If objRow.Cells(2).Range.Text = Chr(13) & Chr(7) Then
      objRow.Cells.Merge
    End If
  Next
Next
End Sub
 
Yes. The var is a leftover from something that was in the original code, in the original thread. For the use here, there is no need for it, and it can be removed. In fact, var in the example code here does nothing except increase by 1.

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top