Results 1 to 3 of 3

Thread: Splitting a particluar column into multiple rows

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Jun 2023
    Posts
    1
    Location

    Splitting a particluar column into multiple rows

    Hi.
    I'm brand new to VBA, but have coded in VB before.
    In Microsoft Word, starting with a table of 33 rows and 3 columns, I want to split each of the initial 33 rows (of column 3 only) into 10 rows each.
    I thought this would be pretty easy, but the code (below) doesn't work. It actually works for the first 2 (of the original) rows, but then the count somehow gets messed up and the third original row doesn't work. I'm not sure why (the count will continue to increase as I am adding 10 rows at a time). As well, the routine ends with no error messages and the job is not complete (except for the first two original rows).

    The code I'm using:

    Sub SplitColumnIntoRows()
    ' In Microsoft Word, split each of the initial 33 rows (of column 3 only) into 10 rows each.
    Dim tbl As Table
        Dim row As Integer
        Dim rowCount As Integer
        Dim col As Integer
    ' Set the table reference to my specific table
        Set tbl = ActiveDocument.Tables(1)
    ' Loop through the appropriate cell in the table (column 3 only)
        col = 3
    rowCount = tbl.Columns(col).Cells.Count
    For row = 1 To rowCount Step 10
    tbl.cell(row, col).Select
    ' Split cell into desired number of rows
            Selection.Cells.Split NumRows:=10, NumColumns:=1
            rowCount = tbl.Columns(col).Cells.Count
        Next
    End Sub
    Any illumination would be helpful.
    Thank you in advance.
    Last edited by Aussiebear; 06-10-2023 at 12:14 AM. Reason: Added code tags

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •