-2

I have a table with 5 columns. Only the first row has 4 columns, the first row first column is merged. I want to delete the 4th column of each row. But because of the mixed cell widths I receive run time error 5992.

looked at this solution: How to access columns in a table that have different cell widths from MS Word

The code is not for VBA

Ally
  • 3
  • 2
  • *"I want to delete the 4th column of each row"* - Wouldn't that be the same as just deleting the 4th column? – dwirony Jan 10 '19 at 22:13
  • 1
    Please update your question with your existing code and if possible a screenshot of the table layout. – Tim Williams Jan 10 '19 at 22:16
  • That not-VBA code isn't VBA indeed, but shouldn't be too hard to translate since it's using the same object model. What have you tried? Please read [*Why is “Can someone help me?” not an actual question?*](https://meta.stackoverflow.com/q/284236/1188513) – Mathieu Guindon Jan 10 '19 at 22:26
  • This seems to be the solution , But I don't know how to code this in VBA https://stackoverflow.com/questions/21316722/deleting-columns-from-a-table-with-merged-cells?rq=1 – Ally Jan 10 '19 at 22:38

1 Answers1

0

Try something based on:

Sub Demo()
Application.ScreenUpdating = False
Dim r As Long
With ActiveDocument.Tables(1)
  For r = 2 To .Rows.Count
    With .Rows(r)
      If .Cells.Count > 3 Then .Cells(4).Delete
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub
macropod
  • 12,757
  • 2
  • 9
  • 21
  • Yes!!!! PERFECT, when you have time, maybe you can help me to understand how you got around the mixed cell width errors – Ally Jan 11 '19 at 19:08
  • The macro tests each row; it doesn't do column-wise processing. The line If .Cells.Count > 3 Then .Cells(4).Delete tests whether there are at least 4 cells on a given row and, if so, deletes the 4th cell from that row. – macropod Jan 11 '19 at 21:18