[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 546
  • Last Modified:

Split big table several times on certain criterion

Dear Experts:

I got a big table spanning over a lot of pages.

I would like to achieve the following using a VBA macro:

The macro should perform the following tasks:

... to look for an entry in column A and ...
... whenever it hits an entry on Column A select that row and SPlIT the table
... since there are numerous enries in Column A of the table several splits are to be performed
... the table splittings automatically result in blank paragraphs.
... now the macro should insert page breaks (Ctrl + Enter) on these blank paragraphs.

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

I have attached a sample file for your convenience with before macro / after macro

Regards, Andreas

  • 2
1 Solution
See if this macro works for you:

Sub SplitTable()
Dim t As Table
Dim r As Integer
Dim tc As Integer
Dim c As String

tc = 1

Set t = ActiveDocument.Tables(1)
  For r = 1 To t.Rows.Count
    c = Len(t.Cell(r, 1).Range.Text)
      If c > 2 Then
        t.Cell(r, 1).Select
          Selection.InsertBreak Type:=wdPageBreak
            tc = tc + 1
          Set t = ActiveDocument.Tables(tc)
        r = 2
      End If
  Next r
End Sub

Open in new window

AndreasHermleAuthor Commented:
Hi flyster,

great coding! Works like a charm, I wanted it exactly this way. Great!

Thank you very much for your professional job.

Regards, Andreas

Thanks for the kind words. I'm happy it worked the way you wanted.


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now