Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-02-2025, 05:31 AM
ranjan ranjan is offline Table formatting issue: Windows 10 Table formatting issue: Office 2019
Advanced Beginner
Table formatting issue:
 
Join Date: May 2021
Posts: 80
ranjan is on a distinguished road
Default Table formatting issue:

Table formatting issue:



Need word VBA macro:

Table cells has spitted into multiple cells within a cell that presented in …. Grid lines.

I want to remove the …. Gridlines within that table border and merged that text which is separated with … Gridlines.

Please see the attachment for the better understanding.

Text within the complete table cells border has to be merged and removed the … grid lines border with the complete border of the cell.

Your Help is Highly appreciated.
Attached Images
File Type: jpg test.JPG (153.3 KB, 13 views)
Attached Files
File Type: docx test.docx (88.3 KB, 4 views)
Reply With Quote
  #2  
Old 05-02-2025, 07:24 AM
Charles Kenyon Charles Kenyon is offline Table formatting issue: Windows 11 Table formatting issue: Office 2021
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,471
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Gridlines or borders?


The way you remove gridlines (which do not print) is to merge cells. I am not sure you want to do that.

To merge cells, select the cells and use the button to merge cells on the Table Layout tab. You can delete text you do not want.

(I moved your post to the Word Tables forum.)
Reply With Quote
  #3  
Old 05-02-2025, 12:36 PM
ranjan ranjan is offline Table formatting issue: Windows 10 Table formatting issue: Office 2019
Advanced Beginner
Table formatting issue:
 
Join Date: May 2021
Posts: 80
ranjan is on a distinguished road
Default

Manually removing gridlines (which do not print) is to merge cells.

There are so many tables in a document. Adjusting and merging each cells taking more time can we automate this task...

Taking more time for merging the ...... grid lines within in the complete cell borders. Please review the attachment once.
Reply With Quote
  #4  
Old 05-02-2025, 04:09 PM
macropod's Avatar
macropod macropod is offline Table formatting issue: Windows 10 Table formatting issue: Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,375
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

Try:
Code:
Sub CellMerge()
Application.ScreenUpdating = False
Dim Tbl As Table, Cll As Cell
For Each Tbl In ActiveDocument.Tables
  For Each Cll In Tbl.Range.Cells
    With Cll
      If .ColumnIndex < Tbl.Columns.Count Then
        If .Borders(wdBorderBottom).LineStyle = wdLineStyleNone And _
          .Borders(wdBorderTop).LineStyle = wdLineStyleNone Then
          .Merge MergeTo:=Tbl.Cell(Row:=.RowIndex + 1, Column:=.ColumnIndex)
          .Merge MergeTo:=Tbl.Cell(Row:=.RowIndex - 1, Column:=.ColumnIndex)
        End If
      End If
    End With
  Next
Next
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 05-03-2025, 12:11 PM
ranjan ranjan is offline Table formatting issue: Windows 10 Table formatting issue: Office 2019
Advanced Beginner
Table formatting issue:
 
Join Date: May 2021
Posts: 80
ranjan is on a distinguished road
Default

Hi,

Thanks for the response.

There are some issues like table has not having same inner grid lines which do not print for each cell borders. some cells have inner grid which do not print and some cells might not have.

I have tried the below code to encounter the two errors while executing a macro:

1. Requested member of the collection does not exist error at For j = 1 To tbl.Rows(i).Cells.count

2. cannot access individual rows in this collection because the table has vertically merged cells error at For j = 1 To tbl.Rows(i).Cells.count

Code:
Sub CellMerge()
    Dim doc As Document
    Dim tbl As Table
    Dim nestedTbl As Table
    Dim i As Integer
    Dim j As Integer
    
    ' Set the document to the active document
    Set doc = ActiveDocument
    
    ' Ensure there is at least one table in the document
    If doc.Tables.Count > 0 Then
        ' Reference the first table
        Set tbl = doc.Tables(1)
        
        ' Loop through each row in the main table
        For i = 1 To tbl.Rows.Count
            ' Loop through each cell in the row
            For j = 1 To tbl.Rows(i).Cells.Count
                ' Check if the cell contains a nested table
                If tbl.Rows(i).Cells(j).Tables.Count > 0 Then
                    ' Reference the nested table
                    Set nestedTbl = tbl.Rows(i).Cells(j).Tables(1)
                    
                    ' Perform operations on the nested table
                    ' Example: Print the number of rows in the nested table
                    Debug.Print "Nested Table in Row " & i & ", Cell " & j & " has " & nestedTbl.Rows.Count & " rows."
                    
                    ' Example: Merge cells in the nested table if needed
                    If nestedTbl.Rows.Count > 1 Then
                        nestedTbl.Cell(1, 1).Merge nestedTbl.Cell(1, 2)
                    End If
                End If
            Next j
        Next i
    Else
        MsgBox "No tables found in the document."
    End If
End Sub
Macro has to be applied on the active table only not on all the tables in a document and macro has to be removed or merge the inner grid lines which do not print within the cell borders which are to be printed. after remove or merged this inner grids which do not print within the border apply find = "^p" replace ="" (no space) remove paragraphs for the merged cells.

Please review the code and am attaching new attachment for the reference please review once.

Any other idea or suggestion would be highly appreciated.


Manually merging each cells in a table was taking more time, your help is highly appreicated.

PLEASE REVIEW THE ATTACHMENT WITH THE NAME TEST2

THANKS IN ADVANCE............
Attached Files
File Type: docx TEST 2.docx (24.5 KB, 4 views)

Last edited by ranjan; 05-03-2025 at 08:45 PM.
Reply With Quote
  #6  
Old 05-04-2025, 02:40 AM
macropod's Avatar
macropod macropod is offline Table formatting issue: Windows 10 Table formatting issue: Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,375
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

Well, you did say the document has multiple tables and you only supplied one example and you gave no indication that other tables might be formatted differently or that you didn't want the macro to process all of them. So that's all I had to code for.

If you want the code to only run on the selected table(s), simply change 'ActiveDocument' to 'Selection'.

Given that you seem to have a variety of tables with different structures, you'll probably need a differernt macro for each structure.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
table borders



Similar Threads
Thread Thread Starter Forum Replies Last Post
Table formatting issue: Table Formatting Issue tomohawk Excel 2 02-03-2023 08:24 AM
Table formatting issue: Irritating formatting issue in Table of Contents - page number "dots" disappear Eriks Word 9 04-19-2019 06:18 PM
Table formatting issue: Table style - first, last and odd column formatting issue BartS Word Tables 2 08-16-2016 04:10 AM
TOC Formatting Issue Caroline Word 1 03-15-2011 01:59 PM
TOC Formatting Issue Angstromm Word 0 09-22-2010 11:49 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:53 AM.


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