Delete the last column of the second table in every section by means of a Macro

Dear Experts:

My current document has the following make-up

  • Lots of section breaks
  • Each section has got exactly two tables

A macro should delete the last column of the second table of each and every section.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
Andreas HermleTeam leaderAsked:
Who is Participating?
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Please give this a try...

Sub DeleteLastColoumn()
Dim doc As Document
Dim sect As Section
Dim tbl As Table

Set doc = ActiveDocument
For Each sect In doc.Sections
    On Error Resume Next
    Set tbl = sect.Range.Tables(2)
    On Error GoTo 0
    If Not tbl Is Nothing Then
        tbl.Columns(tbl.Columns.Count).Delete
    End If
    Set tbl = Nothing
Next sect
End Sub

Open in new window

0
 
Andreas HermleTeam leaderAuthor Commented:
Hi Subodh,

thank you very much for your swift help. I will test it tonight and then let you know :-)
0
 
Andreas HermleTeam leaderAuthor Commented:
Great job, thank you very much for it.

Regards, Andreas
0
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Andreas!
Thanks for the feedback.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.