Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-27-2014, 10:34 PM
macropod's Avatar
macropod macropod is offline Complex table issues - cells shift Windows 7 32bit Complex table issues - cells shift Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,487
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

A significant part of the issue you're having is that your table appears to be comprised of tables cut & pasted into Word with a variety of Table Styles, each with their own alignments, etc. The following macro should be able to clean them up.


Code:
Sub RepairTbl()
Dim i As Long, j As Long, Tbl As Table
Dim pWdth As Single, sCWdth As Single, bkClr As Long
With ActiveDocument
  Set Tbl = .Tables(1)
  With Tbl
    .AllowAutoFit = False
    .Cell(1, 1).PreferredWidthType = wdPreferredWidthPoints
    pWdth = .Cell(1, 1).PreferredWidth
    With .Range
      On Error Resume Next
      For i = .Cells.Count To 1 Step -1
        If .Cells(i).ColumnIndex = 1 Then
          Tbl.Split Tbl.Range.Cells(i).RowIndex
        End If
      Next
      On Error GoTo 0
    End With
  End With
  For Each Tbl In .Tables
    With Tbl
      .AllowAutoFit = False
      With .Rows
        .Alignment = wdAlignRowLeft
        .LeftIndent = 0
        .WrapAroundText = False
      End With
    End With
  Next
  For i = 1 To .Tables.Count
    sCWdth = 0
    With .Tables(i)
      .AllowAutoFit = False
      .PreferredWidthType = wdPreferredWidthPoints
      .PreferredWidth = pWdth
      With .Range
        If .Cells.Count = 1 Then
          bkClr = .Cells(1).Shading.BackgroundPatternColorIndex
        End If
      End With
      .Style = "Table Normal"
      With .Range
        For j = 1 To .Cells.Count
          sCWdth = sCWdth + .Cells(j).Width
        Next
        If sCWdth <> pWdth Then
          For j = 1 To .Cells.Count
            .Cells(j).Width = .Cells(j).Width * pWdth / sCWdth
          Next
        End If
        If .Cells.Count = 1 Then
          If bkClr <> 0 Then .Cells(1).Shading.BackgroundPatternColorIndex = bkClr
        End If
      End With
    End With
  Next
  While .Tables.Count > 1
    .Tables(1).Range.Characters.Last.Next.Select
    Selection.Delete
  Wend
  With .Tables(1)
    .Borders.Enable = True
    .Rows.Alignment = wdAlignRowCenter
  End With
End With
End Sub
PS: Cut & paste the problem table to another document for processing. Once processed, you can copy it back to the source document.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 06-30-2014, 10:48 AM
Cosmo Cosmo is offline Complex table issues - cells shift Windows Vista Complex table issues - cells shift Office 2007
Competent Performer
Complex table issues - cells shift
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
A significant part of the issue you're having is that your table appears to be comprised of tables cut & pasted into Word with a variety of Table Styles, each with their own alignments, etc. The following macro should be able to clean them up.
...
PS: Cut & paste the problem table to another document for processing. Once processed, you can copy it back to the source document.
Thanks again for your continued assistance (and somewhat superhuman patience). I tried running your code on the table I had created on Friday, and it had an error at line 48 (.Cells(j).width = .Cells(j).width * pWdth / sCWdth). I used a variable to set the value, and the error did not occur, but the result is still problematic (many rows are not the correct length, and if I try to adjust them, the rest of the rows shift more).

The file I created Friday had no tables or cells that were copied and pasted (each table section was from a brand new created table); the only items copied was the text from the original source document (InDesign). I spent most of the day meticulously creating and adjusting each table. I'm attaching that file if you want to look at that (I cleared the contents of the cells). This is where I had gotten to when the problems started reoccurring. When I tried to join the last 2 tables, the cells in the last table shift again. They are correct before the tables are joined. Any editing after joining the tables compounds the shifting cells.

Many rows (and cells) require different cell margins (these were set manually in the cell margins dialog, not by cutting and pasting), and that appears to me to be what was causing the shifting in the Outline view, don't know if that has anything to do with the different table styles you mentioned.
Attached Files
File Type: docx Table3.docx (38.8 KB, 13 views)
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Complex table issues - cells shift Word 2007 Table - Shift Cells INDYBUG Word Tables 1 09-29-2013 05:47 PM
How to make rows or cells shift down automatically rfrontz Excel 1 04-16-2013 03:26 AM
Complex table issues - cells shift How to make cells shift down automatically iffy Excel 7 04-15-2013 08:06 AM
Counting cells with multiple complex criteria TishyMouse Excel 12 12-06-2012 05:05 AM
Complex table issues - cells shift Word 2007 Tables - Shift cells backwards one place bloodge1 Word Tables 3 08-28-2012 10:11 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:10 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