View Single Post
 
Old 09-01-2018, 05:40 AM
jeffreybrown jeffreybrown is offline Windows Vista Office 2007
Expert
 
Join Date: Apr 2016
Posts: 673
jeffreybrown has a spectacular aura aboutjeffreybrown has a spectacular aura about
Default Merge the first row in a table

I'm converting PDFs to Word and most tables in the document have merged rows, but not sure how many columns. They all differ.

I'm adding a row to the top of the table, but then it needs to be merged. I've found the macro to add the row, but can't find how to merge it to the entire row. I did find a macro to merge, by only the first two columns. How can I find the end of the table for the first row to merge the first row no matter how many columns?

Code:
Sub Add_Rows_Table()
    Application.ScreenUpdating = False
    Dim Tbl As Table, Rng As Range
    For Each Tbl In ActiveDocument.Tables
        Tbl.Cell(1, 1).Range.Select
        Selection.InsertRowsAbove 1
    Next Tbl
    Application.ScreenUpdating = True
End Sub
Code:
Sub Test_This()
    Dim mrgrng As Range
    With Selection.Tables(1)
        Set mrgrng = .Cell(1, 1).Range
        mrgrng.End = .Cell(1, 2).Range.End
        mrgrng.Cells.Merge
    End With
End Sub
If possible, I would also like to see if the text above the table which starts with Table can be added into the new table row and all but the bottom border to remain.

Note: It seems the overall problem is the vertically merged cells. I can't seem to find how to work around the vertically merged cell to format the newly added first row of the table.
Attached Files
File Type: docx Before and After - Table.docx (15.2 KB, 11 views)

Last edited by jeffreybrown; 09-01-2018 at 07:47 AM.
Reply With Quote